I am trying to write a query in visual basic that will select records from a table where two variable conditions are both met, and which will then insert these records into another table. The query I have written is:
strSQL = "INSERT INTO [stocksearch] ([CustomerID], [ProductCode], [Quantity]) " & _
"SELECT * " & _
"FROM [stock] " & _
"WHERE [Stock].[CustomerID] = " & custSearch & " and [Stock].[ProductCode] = " & prodSearch & " "
Set dbfSalesdata = DBEngine.Workspaces(0).OpenDatabase(SALESDATA_PATH)
dbfSalesdata.Execute (strSQL)
As far as I can see this is identical to other successful queries I have written, and yet it produces a "syntax error missing operator" error. I am guesssing it is the variables (custSearch and prodSearch) that are causing the problems, but I have tried every combination of brackets, commas, quotes etc that I can think of and nothing makes it right.
Please can someone tell me what the error is?
Thanks.
Stuart
strSQL = "INSERT INTO [stocksearch] ([CustomerID], [ProductCode], [Quantity]) " & _
"SELECT * " & _
"FROM [stock] " & _
"WHERE [Stock].[CustomerID] = " & custSearch & " and [Stock].[ProductCode] = " & prodSearch & " "
Set dbfSalesdata = DBEngine.Workspaces(0).OpenDatabase(SALESDATA_PATH)
dbfSalesdata.Execute (strSQL)
As far as I can see this is identical to other successful queries I have written, and yet it produces a "syntax error missing operator" error. I am guesssing it is the variables (custSearch and prodSearch) that are causing the problems, but I have tried every combination of brackets, commas, quotes etc that I can think of and nothing makes it right.
Please can someone tell me what the error is?
Thanks.
Stuart