adding data to two tables simultaneously

  • Thread starter Thread starter aptech
  • Start date Start date
A

aptech

i want to add some fields in a form to two tables, so that
both tables reflect the same data in those columns.

i am lost at it. any help is appreciated.
 
First off, why would you want to do this? Will the values
need to *stay* synchronized? If so, just create reference
from on field to another. That being said, here's how to
do it. This would really depend on your table structure,
but the easiest way I can think of is this:

Function DoubleAdder()

Dim dbs as DAO.Database
Dim rst as DAO.Recordset
Dim rst2 as DAO.Recordset

Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("FirstTableNameHere")
Set rst2 = dbs.OpenRecordset("SecondTableNameHere")

rst.AddNew
rst.Fields("FieldNameInFirstTable") = <Control>
rst.Update

rst2.AddNew
rst2.Fields("FieldNameInSecondTable") = <Control>
rst2.Update

rst2.Close
rst2.Close

Set rst = Nothing
Set rst2 = Nothing
Set dbs = Nothing

End Function
 
Back
Top