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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need VB code for a AfterUpdate event procedure.

Status
Not open for further replies.

88lbr

Technical User
Aug 19, 2002
6
US
When I add a new record to the inventory table using a form I need to create 1 new record automatically in the related transaction table. The InventoryID autonumber field is connecting these two tables in the relationships. The InventoryID autonumber is the only data to be shown in the new record. I either need code in the Afterupdate property for the InventoryID field or a command button on the form that will do this.

 
88lbr

You are a little light on details so the answer will be a little light on specifics...

The most difficult issue is to know what the primary key is on the first record and use it (as a foreign key?) for the transaction table.

For the AfterUpdate event procedure, I am going to assume that you have easy access to the primary key for the record just created.

Code:
Dim dbs as DAO.Database, rst as DAO.Recordset

Set dbs = CurrentDB()
Set rst = dbs.Openrecordset("NameOfTransactionTable")

With rst
   .AddNew
      !ForeignKey = Me.PrimaryKeyFromForm
      '!AnotherField = ....
      'etc...
   .Update
End rst

rst.Clost
dbs.Clost
Set rst = Nothing
Set dbs = Nothing

I am assuming that the primary key for the transaction table will be generated at insertion. Otherwise, you have to grab it too when creating the record.

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top