Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Access VBA SQL - Add records to two linked tables

Hi
In my Access VBA SQL code I need to add records to two linked tables: "Orders" and "Order Details".
I need to first add a record to the "Orders" table. Then I need to use the new number in the "ID" column
of this table and use it to insert records in the "Order Details" table, which has a field called "Order ID".
How do I do this?
Thanks
Avatar of Máté Farkas
Máté Farkas
Flag of Hungary image

You definitely need a key of rows between table Orders And OrderDetails.
For example:
 - You insert Orders with these columns: OrderDate, OrderTime, ClientID
 - You insert OrderDetails with these columns: OrderDate, OrderTime, ClientID, ProductID, Quantity

The you insert data into Orders (and OrderIDs will be generated) and then join data back for OrderDetails to Orders by OrderDate, OrderTime, ClientID (this is the key) and you will get back the OrderID from Orders.
Avatar of Murray Brown

ASKER

Hi. Thanks. I should have clarified that I am looking for the VBA code to do this
ASKER CERTIFIED SOLUTION
Avatar of Fabrice Lambert
Fabrice Lambert
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much