Jeff Heilman
asked on
MS Access 2013 insert query runtime error 3134
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.
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
ASKER
Thanks for the response samo! Same issue though. When I hit "Debug" it highlights line 27, DoCmd.RunSQL strSql
Insert a debug line and watch the output:
Debug.Print strSql
DoCmd.RunSQL strSql
It could be Null values.
/gustav
Debug.Print strSql
DoCmd.RunSQL strSql
It could be Null values.
/gustav
Just notice the Date and Name column s, could be the reserved word issue change it to [Date] and [Name] and try
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:
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 & ")"
ASKER
Thanks Gustav, I don't see any null values messing it up. This really has me puzzled.
If you reveil the outputted strSql perhaps we could see something ...
/gustav
/gustav
ASKER
Here is the output from the Immediate window:
Thanks everyone for your help so far.
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')
Thanks everyone for your help so far.
ASKER
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')
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey, that fixed it! I feel pretty stupid right now. Thanks a million Gustav!
You are welcome!
/gustav
/gustav
replace line 25 with
Open in new window