Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I add data to more than one Table

Access Howto:

How do I add data to more than one Table

by  DougP  Posted    (Edited  )
this example shows how to add data to 3 tables at the same time using VBA code.
--------------------------
Dim db As Database
Dim rst1 As Recordset
Dim rst2 As Recordset
Dim rst3 As Recordset

Set db = CurrentDb
Set rst1 = db.OpenRecordset("Table1")
Set rst2 = db.OpenRecordset("Table2")
Set rst3 = db.OpenRecordset("Table3")

rst1.AddNew
rst1!Yourfield = Somedata '<<<<<<< put data into table1
rst1!Yourfield2 = Somedata2
rst1.Update

rst2.AddNew
rst2!Yourfield = Somedata '<<<<<<< put data into table2
rst2!Yourfield2 = Somedata2
rst2.Update

rst3.AddNew
rst3!Yourfield = Somedata '<<<<<<< put data into table3
rst3!Yourfield2 = Somedata2
rst3.Update

rst1.Close
rst2.Close
rst3.Close
db.Close
-----------------------------------------
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top