Solved

MS Access 2013 insert query runtime error 3134

Posted on 2014-10-15
12
221 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SharePoint 2013 Relational Database 8 23
Syntax using Declare 3 16
Merge Statement 3 0
Stored Procedure 2 0
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now