Occurs when a form is about to be removed from the screen.
Private Sub Form_Unload(cancel)
The Unload event syntax has these parts:
Part | Description |
---|---|
object | An object expression that evaluates to an object. |
cancel | An integer. Setting this argument to any value other than 0 stops the Unload event in all loaded forms and stops the form and application from closing. |
Use an Unload event procedure to verify that the form should be unloaded or to specify actions that you want to take place when the form is unloaded. You can also include any form-level validation code you may need for closing the form or saving the data in it to a file.
When an application closes, you can use either the QueryUnload or Unload event procedure to set the Cancel property to True, stopping the closing process. However, the QueryUnload event occurs in all forms before any are unloaded, and the Unload event occurs as each form is unloaded.