title | keywords | f1_keywords | api_name | ms.assetid | ms.date | ms.localizationpriority | ||
---|---|---|---|---|---|---|---|---|
Form.AfterInsert event (Access) |
vbaac10.chm13636 |
|
|
07140c13-ce7c-91f2-7451-d7f834653ef2 |
03/08/2019 |
medium |
The AfterInsert event occurs after a new record is added.
expression.AfterInsert
expression A variable that represents a Form object.
Nothing
Note
Setting the value of a control by using a macro or Visual Basic doesn't trigger these events.
Use an AfterInsert event procedure or macro to requery a recordset whenever a new record is added.
To run a macro or event procedure when the AfterInsert event occurs, set the OnAfterInsert property to the name of the macro or to [Event Procedure].
This example shows how you can use a BeforeInsert event procedure to verify that the user wants to create a new record, and an AfterInsert event procedure to requery the record source for the Employees form after a record has been added.
To try the example, add the following event procedure to a form named Employees that is based on a table or query. Switch to form Datasheet view and try to insert a record.
Private Sub Form_BeforeInsert(Cancel As Integer)
If MsgBox("Insert new record here?", _
vbOKCancel) = vbCancel Then
Cancel = True
End If
End Sub
Private Sub Form_AfterInsert()
Forms!Employees.Requery
End Sub
[!includeSupport and feedback]