RecordExit Event
Occurs just before the user exits the current record.
Private Sub Form_RecordExit(Cancel As Integer)
Cancel Set this argument to True to prevent the user from exiting the current record.
Remarks
The event occurs after the user has done something to move away from the current record, either by navigating to another record, closing the form, refreshing the form, or requerying the form, but before the view of the current record has been discarded. Use this event to examine records before they are no longer the current record to ensure that data validation rules have been met.
Note When a form containing a subform is closed, the main form closes before the subform. Any events triggered by the subform, including RecordExit, occur after the main form is already closed. As a result, the Cancel argument will have no effect and the form will close. Event-driven validation should therefore be implemented at the form level.
Example
The following example demonstrates the syntax for a subroutine that traps the RecordExit event.
Private Sub Form_RecordExit(Cancel As Integer)
Dim booValidated As Boolean
' Perform some sort of data validation.
If booValidated = True Then
Cancel = False
Else
MsgBox "Data validation failed!"
Cancel = True
End If
End Sub