It triggers it ONLY if there is anything to update. If nothing has been done to the form, that code will not get past the If Me.Dirty because it already is false.
After Insert is distinct from AfterUpdate -- and it occurs only when you "dirty" a brand new record (as opposed to starting to edit an existing record). When you dirty a new record, you are "inserting" a new record and that is when BeforeInsert/AfterInsert events fires. So by the time you see your first character appear on the screen, both event already has happened.
One possible idea to help you see how events fire in sequence, other than looking in the help document -- there was a magic keyword that would get the right document that gives you list of event sequence but I can't remember it at the moment -- is to add messagebox to each event you're interested then futz with the form a bit to see how it fires and when.
Form BeforeInsert
Form Dirty
Form BeforeUpdate
Form AfterUpdate
Form AfterInsert
If you're updating an existing row, BeforeInsert and AfterInsert do not occur. BeforeInsert occurs on a new row the instant the user types any character or chooses a value from a bound combo box or list box.
Private Sub Form_BeforeInsert(Cancel As Integer)
If IsNull(Me.Parent.Pkey) Then
MsgBox "You must enter data in X (the parent table) " & _
before creating a Y (the subform table). Press Esc " & _
"to clear your edit.", vbInformation
Cancel = True
End If
End Sub
Actually, Dirty doesn't get set, so telling the user to press Esc is unnecessary. After disabling the Form_Current event in Northwind 2007 Order Details, this works just fine:
Code:
Private Sub Form_BeforeInsert(Cancel As Integer)
If IsNull(Me.Parent![Order ID]) Then
MsgBox "You must enter Order information before you can select products."
Me.Parent![Customer ID].SetFocus
Cancel = True
End If
End Sub
I have very rarely used the Enter event for anything. The one example I have in my books is to use Enter for the first control on the second page of a multi-page form to align to the top of that page.