Including a variable in an Append (Insert) query

R

Rafi

I have the following VBA code that is supposed to insert values into a table
based on a select statement and a variable. lngID is a variable that is
being defined earlier in the coe.

What am I doing wrong here? Thanks in advance for your help



stSQL = "INSERT INTO tblProjectData ( Error, SKU, DESC, MVMT, UOM, HEIGHT,
WIDTH," _
& " LENGTH, WEIGHT, AVG_UOH, AVG_UC, LEAD_TIME, ProectID )" _
& " SELECT Temp2.Error, Temp2.sku, Temp2.desc, temp2.mvmt,
Temp2.uom," _
& " Temp2.height, Temp2.width, Temp2.length, Temp2.weight," _
& " Temp2.[avg uoh], Temp2.[avg uc], Temp2.[lead time]," & lngID _
& " FROM Temp2;"
 
J

John W. Vinson

What am I doing wrong here? Thanks in advance for your help

I don't know. What's going wrong? Error message? Not inserting anything?
inserting incorrect value? inserting gibberish?

stSQL = "INSERT INTO tblProjectData ( Error, SKU, DESC, MVMT, UOM, HEIGHT,
WIDTH," _
& " LENGTH, WEIGHT, AVG_UOH, AVG_UC, LEAD_TIME, ProectID )" _
& " SELECT Temp2.Error, Temp2.sku, Temp2.desc, temp2.mvmt,
Temp2.uom," _
& " Temp2.height, Temp2.width, Temp2.length, Temp2.weight," _
& " Temp2.[avg uoh], Temp2.[avg uc], Temp2.[lead time]," & lngID _
& " FROM Temp2;"

What's the value of sSQL when you step through the code?
 
R

Rafi

Run-Time Error 3134 - syntax error in INSERT INTO Statement



John W. Vinson said:
What am I doing wrong here? Thanks in advance for your help

I don't know. What's going wrong? Error message? Not inserting anything?
inserting incorrect value? inserting gibberish?

stSQL = "INSERT INTO tblProjectData ( Error, SKU, DESC, MVMT, UOM, HEIGHT,
WIDTH," _
& " LENGTH, WEIGHT, AVG_UOH, AVG_UC, LEAD_TIME, ProectID )" _
& " SELECT Temp2.Error, Temp2.sku, Temp2.desc, temp2.mvmt,
Temp2.uom," _
& " Temp2.height, Temp2.width, Temp2.length, Temp2.weight," _
& " Temp2.[avg uoh], Temp2.[avg uc], Temp2.[lead time]," & lngID _
& " FROM Temp2;"

What's the value of sSQL when you step through the code?
 
J

John W. Vinson

Try putting LENGTH, ERROR and HEIGHT in square brackets; I'm not sure but they
may be reserved words.
Run-Time Error 3134 - syntax error in INSERT INTO Statement



John W. Vinson said:
What am I doing wrong here? Thanks in advance for your help

I don't know. What's going wrong? Error message? Not inserting anything?
inserting incorrect value? inserting gibberish?

stSQL = "INSERT INTO tblProjectData ( Error, SKU, DESC, MVMT, UOM, HEIGHT,
WIDTH," _
& " LENGTH, WEIGHT, AVG_UOH, AVG_UC, LEAD_TIME, ProectID )" _
& " SELECT Temp2.Error, Temp2.sku, Temp2.desc, temp2.mvmt,
Temp2.uom," _
& " Temp2.height, Temp2.width, Temp2.length, Temp2.weight," _
& " Temp2.[avg uoh], Temp2.[avg uc], Temp2.[lead time]," & lngID _
& " FROM Temp2;"

What's the value of sSQL when you step through the code?
 
Top