How do I copy data from another table using SQL in Access VBA

时间:2018-03-22 23:47:40

标签: vba ms-access access-vba

Below is my code. Can anyone help? SQL1 runs well but SQL2 Gives me a run time error 3075 (missing operator) in query expression '*StockNo'.

Private Sub DataUpdate()
Dim SQL1 As String
Dim SQL2 As String

SQL1 = "UPDATE tblChemicalStock " & _
       "INNER JOIN tblChemicalStock1 " & _
"ON(tblChemicalStock.ChemicalName = tblChemicalStock1.ChemicalName) " & _
"SET tblChemicalStock.Stock1 = tblChemicalStock1.Stock1, " & _
"tblChemicalStock.Stock2 = tblChemicalStock1.Stock2, " & _
"tblChemicalStock.TotalStock = tblChemicalStock1.TotalStock;"

 DoCmd.RunSQL SQL1

 SQL2 = "INSERT INTO tblChemicalStock ([StockNo],[ChemicalName],[Stock1], 
[Stock2],[TotalStock],[CategoryCode])" & _
"SELECT *StockNo,ChemicalName,Stock1,Stock2,TotalStock,CategoryCode FROM tblChemicalStock1 t" & _
"WHERE NOT EXISTS(SELECT 1 FROM tblChemicalStock s" & _
"WHERE t.StockNo = s.StockNo);"

DoCmd.RunSQL SQL2

End Sub

0 个答案:

没有答案