Solved

MS Access 2013 insert query runtime error 3134

Posted on 2014-10-15
12
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe 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 85
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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