Solved

MS Access 2013 insert query runtime error 3134

Posted on 2014-10-15
12
228 Views
Last Modified: 2014-10-16
Hello,

I've been over this code a dozen times and cannot figure out why it doesn't work.  I use the same code in another MS Access 2013 database with no issues.  All it does is insert filtered data to a local table for reporting purposes.   When I try to run the code I get a Run Time Error 3134, Syntax error in INSERT INTO statement.  Any help would be great.

'****Clear and populate tblDieWork with filtered data only****

Dim strWhere As String

Dim strSql As String

strWhere = Me.txtStrFilter

If IsNull(strWhere) Or strWhere = "" Then
    ' Nothing
Else
    strWhere = "WHERE " & strWhere
End If

'DoCmd.SetWarnings False

strSql = "DELETE FROM tblDieWork"
DoCmd.RunSQL strSql

strSql = "INSERT INTO tblDieWork (Extruder, DieMaster, DieID, OldItem, WtFt, FtMin, Shift, Name, MaintNotes, "
strSql = strSql & "Operator, Date, ExtruderDayID, ScanNewProdID, Material, CapMaterial, RepairDate, RepairDesc, RepairTech, CloseOrder ) "

strSql = strSql & "SELECT qryDieWork.Extruder, qryDieWork.DieMaster, qryDieWork.DieID, qryDieWork.OldItem, qryDieWork.WtFt, qryDieWork.FtMin, qryDieWork.Shift, qryDieWork.Name, qryDieWork.MaintNotes, "
strSql = strSql & "qryDieWork.Operator, qryDieWork.Date, qryDieWork.ExtruderDayID, qryDieWork.ScanNewProdID, qryDieWork.Material, qryDieWork.CapMaterial, qryDieWork.RepairDate, qryDieWork.RepairDesc, qryDieWork.RepairTech, qryDieWork.CloseOrder "
strSql = strSql & "FROM qryDieWork " & strWhere

DoCmd.RunSQL strSql
DoCmd.SetWarnings True

End Sub

Open in new window

0
Comment
Question by:jeff-h
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40382844
Hello,

replace line 25 with

strSql = strSql & "FROM qryDieWork " & strWhere & " ;" 

Open in new window

0
 

Author Comment

by:jeff-h
ID: 40382861
Thanks for the response samo!  Same issue though.  When I hit "Debug" it highlights line 27, DoCmd.RunSQL strSql
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40382886
Insert a debug line and watch the output:

    Debug.Print strSql
    DoCmd.RunSQL strSql

It could be Null values.

/gustav
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40382903
Just notice the Date and Name column s, could be the reserved word issue change it to [Date] and [Name] and try
0
 
LVL 84
ID: 40382953
You don't need the trailing semicolon.

Most likely there's something wrong with the SELECT portion of your query. Try running that separately using the same method gustav suggests:

Debug.Print strSQL

Copy the SELECT portion of that SQL into a new query window, and see if it runs correctly. To do that, open a new query, don't add any tables, and then select the SQL view. Switch over to Design or Datasheet view and see if you encounter any errors.

I've also had to enclose the sub-Select in parentheses:

strSql = strSql & " (SELECT qryDieWork.Extruder, qryDieWork.DieMaster, qryDieWork.DieID, qryDieWork.OldItem, qryDieWork.WtFt, qryDieWork.FtMin, qryDieWork.Shift, qryDieWork.Name, qryDieWork.MaintNotes, "
strSql = strSql & "qryDieWork.Operator, qryDieWork.Date, qryDieWork.ExtruderDayID, qryDieWork.ScanNewProdID, qryDieWork.Material, qryDieWork.CapMaterial, qryDieWork.RepairDate, qryDieWork.RepairDesc, qryDieWork.RepairTech, qryDieWork.CloseOrder "
strSql = strSql & "FROM qryDieWork " & strWhere & ")"

Open in new window

0
 

Author Comment

by:jeff-h
ID: 40382954
Thanks Gustav, I don't see any null values messing it up.  This really has me puzzled.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40382983
If you reveil the outputted strSql perhaps we could see something ...

/gustav
0
 

Author Comment

by:jeff-h
ID: 40384990
Here is the output from the Immediate window:

INSERT tblDieWork (Extruder, DieMaster, DieID, OldItem, WtFt, FtMin, Shift, [Name], MaintNotes, Operator, [Date], ExtruderDayID, ScanNewProdID, Material, CapMaterial, RepairDate, RepairDesc, RepairTech, CloseOrder)  (SELECT qryDieWork.Extruder, qryDieWork.DieMaster, qryDieWork.DieID, qryDieWork.OldItem, qryDieWork.WtFt, qryDieWork.FtMin, qryDieWork.Shift, [qryDieWork].[Name], qryDieWork.MaintNotes, qryDieWork.Operator, [qryDieWork].[Date], qryDieWork.ExtruderDayID, qryDieWork.ScanNewProdID, qryDieWork.Material, qryDieWork.CapMaterial, qryDieWork.RepairDate, qryDieWork.RepairDesc, qryDieWork.RepairTech, qryDieWork.CloseOrder FROM qryDieWork WHERE DieMaster='CT396')

Open in new window


Thanks everyone for your help so far.
0
 

Author Comment

by:jeff-h
ID: 40384998
Here is the output with both of the criteria used:
INSERT INTO tblDieWork (Extruder, DieMaster, DieID, OldItem, WtFt, FtMin, Shift, [Name], MaintNotes, Operator, [Date], ExtruderDayID, ScanNewProdID, Material, CapMaterial, RepairDate, RepairDesc, RepairTech, CloseOrder)  (SELECT qryDieWork.Extruder, qryDieWork.DieMaster, qryDieWork.DieID, qryDieWork.OldItem, qryDieWork.WtFt, qryDieWork.FtMin, qryDieWork.Shift, [qryDieWork].[Name], qryDieWork.MaintNotes, qryDieWork.Operator, [qryDieWork].[Date], qryDieWork.ExtruderDayID, qryDieWork.ScanNewProdID, qryDieWork.Material, qryDieWork.CapMaterial, qryDieWork.RepairDate, qryDieWork.RepairDesc, qryDieWork.RepairTech, qryDieWork.CloseOrder FROM qryDieWork WHERE DieMaster='V382' AND DieID='B')

Open in new window

0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 40385125
There shall be no parenthesis around the Select statement.

/gustav
0
 

Author Comment

by:jeff-h
ID: 40385188
Hey, that fixed it!  I feel pretty stupid right now.  Thanks a million Gustav!
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40385357
You are welcome!

/gustav
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question