I have 4 tables with a common field, ItemNumber.
Set db = CurrentDb
Set rs1 = db.OpenRecordset("select * from Items;")
Set rs2 = db.OpenRecordset("select * from Stock;")
Set rs3 = db.OpenRecordset("select * from OpenPOMARS;")
Set rs4 = db.OpenRecordset("select * from RequireMARS;")
I want to pull the first ItemNumber from Items and look up and combine data from each of the other three databases.
There are a lot of calculations I'm performing on the data -- too many for a query. So I'm writing a vb program.
The sloppy way is to open up all 4 databases and do Lookups.
The joins are all Left joins. I need ALL the records in Items and whatever records exist in the other tables. When I create a query to cheat of figuring out the SQL statement I get:
SELECT Items.itemId, Items.use, Stock.qStk, OpenPOMARS.*, RequireMARS.*" & _
"FROM ((Items LEFT JOIN Stock ON Items.itemId = Stock.itemId)" & _
"LEFT JOIN OpenPOMARS ON Items.itemId = OpenPOMARS.ItemNumber)" & _
" LEFT JOIN RequireMARS ON Items.itemId = RequireMARS.ItemNumber;"
but when I set it to a variable and do
docmd.runsql variable I get
"A RunSQL action requires a argument consisting of an SQL statement."
My Questions:
1 - Whats wrong with my SQL statement? It works in a Query but not in a program.
2 - And I going about this the right way?
Thank You!