Visual Basic On Close event occurs when a form is closed and removed from
the screen.
On Close Event Example:
This is a subroutine we use often on the main menu of an Access
database to prevent the user from attempting to get into the database objects.
In this example Microsoft Access will exit if the user closes the form.
Private Sub Form_Close()
DoCmd.Quit
End Sub
The event sequence when closing a form is as follows:
Unload → Deactivate → Close