Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Statement not working in VBA

Status
Not open for further replies.

JPinter

Technical User
Aug 15, 2002
9
US
I tried copying two SQL Statements from an append query and delete query, because I want to move all records into a table and then delete the records I moved. It works fine on the querys, and when they were shorter they worked fine in a macro, but I can not get them to work in VBA. Can you tell what is wrong with this statement that it will not work.
Thanks,
Jeff



Private Sub Command63_Click()

Dim SQL As String

SQL = "INTO tblClosedjobs ( Description, [Bin#], Supplier, [Units of Measure], [Min], [Max], [GL#], [GL2#], Cost ) " & _
"SELECT tblPartlbr.*, tblPart.Description, tblPart.[Bin#], tblPart.Supplier, tblPart.[Units of Measure], tblPart.Min, tblPart.Max, tblPart.[GL#], tblPart.[GL2#], tblPart.Cost " & _
"FROM tblPart INNER JOIN tblPartlbr ON tblPart.[Part-Labor#] = tblPartlbr.[Part-Labor#]; " & _
"DELETE tblPartlbr.* " & _
"FROM tblPartlbr;"

DoCmd.RunSQL SQL

End Sub
 
Jeff,

I belive the problem might be that you need to seperate your SQL Statements,

So try this:

Private Sub Command63_Click()

Dim SQL As String

SQL = "INTO tblClosedjobs ( Description, [Bin#], Supplier, [Units of Measure], [Min], [Max], [GL#], [GL2#], Cost ) " & _
"SELECT tblPartlbr.*, tblPart.Description, tblPart.[Bin#], tblPart.Supplier, tblPart.[Units of Measure], tblPart.Min, tblPart.Max, tblPart.[GL#], tblPart.[GL2#], tblPart.Cost " & _
"FROM tblPart INNER JOIN tblPartlbr ON tblPart.[Part-Labor#] = tblPartlbr.[Part-Labor#];

DoCmd.RunSQL SQL

SQL = "DELETE tblPartlbr.* " & _
"FROM tblPartlbr;"

DoCmd.RunSQL SQL
End Sub Kyle

[pacman]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top