Solved

MS Access 2013 insert query runtime error 3134

Posted on 2014-10-15
12
233 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 50

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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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 50

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 50

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 50

Expert Comment

by:Gustav Brock
ID: 40385357
You are welcome!

/gustav
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

730 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