Visual Basic On Exit event occurs just before a control loses the focus to
another control on the same form.
Access Database On Exit Event Example:
Here we show how to do validation on a the Due_Date field of a
form. The Due_Date is a required field and we want to make sure the user
does not leave it blank on exiting. Using the On Exit event for validation
is not fool proof since this event does not always trigger based on the form and
field the user is moving to.
Private Sub LastName_Exit(Cancel As Integer)
If isnull(Me.Due_Date)=True then
Msgbox "The Due Date is a required field."
Me.Due_Date.SetFocus
End If
End Sub
We strongly advice that you don't try to over control
cursor movement on an Access form using the on exit event. In the end you
will encounter errors and Access will prevent you from going to a specific field
or changing data depending on the status of the form.
You'd be
better off using Access 2010's new table-level event triggers to perform most
data validation with the Before Change table event macro capability.