Entering data into multiple access tables

KennyMac
01-08-2004, 02:07 PM
Ok here's my problem!
I have two access tables, Machine and Component. They are connected via a one-to-many relationship(A Machine has one or more components). The primary key Machine_id in the machine table is the foreign key in the Components table.
I have a form in vb within which i wish to add one machine and then add mulitple components. I have three text boxes which show the machine details eg(name, purchase date and cost) I then have a datagrid which should be empty and allow components to be added. The proble is : i can save a machine easily but the machine_id needs to be placed into the Component table to aloow records to be added. Can anyone send me on the right track please???

Optikal
01-08-2004, 02:13 PM
After you insert into the machine table execute the following SQL statement to get the machine_id to use when inserting in the Components table:

SELECT @@Identity FROM Machine

KennyMac
01-08-2004, 03:23 PM
Thanks, I just spoke to someone how suggested the same solution.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum