Solved

MS Access 2013 insert query runtime error 3134

Posted on 2014-10-15
12
229 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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 utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

809 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