Form Event – Visual Basic Code Example
The Form BeforeInsert event happens when the user types the very first character in a form new record, but before the record is actually created in the database table.
BeforeInsert Event Example:
Here we are manually coordinated two continuous forms together. Access will not allow you to do this with dual continuous forms using link master and link child properties. The code below takes the primary key (Trip_Guide_Daily_ID) in the master record and propagates it to the new record in the detail record using the before insert event.
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.Trip_Guide_Daily_ID = Me.Parent.Trip_Guide_Daily_ID
Generally, the before insert event is great for loading values into fields that are not input by the user. For instance a field called User_ID might be added to this record to automagically track who entered the record. See user login example to view how to save special data fields during login for future use.
MS Access 2003