How to insert into two tables?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two tables. tblOne has quite a few of the same fields as tblTwo, so I thought maybe I could automatically insert some of the fields from tblTwo into tblOne at the same time. I have a form for inserting values into tblTwo, now I want to save these values in both tables. How can I do this

Thanks
 
If you need to post the same record to two different
tables, it most likely means that your tables are not well
normalized, which can lead to a series of problems.

Two normalization rules are that a table should represent
one "thing", and that data should be stored in one place
only. For example, I might think to create two tables,
one for Suppliers and one for Customers, each of which has
an address, city, state, phone, etc. Some might be both,
however. If you insert a record into each table, now if
they move, or change area codes, or any other change is
necessary, you'll need to change it in both tables.

Following the above rules, a better design creates a
single table, Companies, a Relationship table that defines
the different kinds of relationships, and a
CompanyRelationship table as follows:

Companies
CompanyID
Address
Etc.

Relationship Example
RelationshipID 1
Relationship Customer

CompanyRelationship
CompanyRelationshipID
CompanyID (Foreign Key to Companies)
RelationshipID (Foreign Key to Relationship)

Companies and CompanyRelationship have a one-to-many
relationship. A single company could be a supplier, a
customer, a consultant, etc.

If you don't think this addresses your current problem,
one way to achieve what you're after is to create an
insert query which uses your form controls as source data,
and execute the query from a Command Button on your form.
The syntax to refer to a form control is:

Forms!yourformname!yourcontrolname (main form)
or
Forms!yourformname!nameofsubformcontrolinmainform.Form!
yoursubformcontrolname

HTH
Kevin Sprinkel


-----Original Message-----
I have two tables. tblOne has quite a few of the same
fields as tblTwo, so I thought maybe I could automatically
insert some of the fields from tblTwo into tblOne at the
same time. I have a form for inserting values into tblTwo,
now I want to save these values in both tables. How can I
do this?
 
Back
Top