BeforeInsert Event

 

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
End Sub

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.

Table Triggers
Form Flags
Table Triggers
Record Flags
Record Events

Microsoft Office:
MS Access 2003
Access 2007
Access 2010
Access 2013
Access 2016