Load, Unload Events - Event Procedures

Load, Unload Events — Event Procedures

See Also         Example

To create an event procedure that runs when the Load or Unload event occurs, set the OnLoad or OnUnload property to [Event Procedure], and click the Build button .

Syntax

Private Sub Form_Load( )

Private Sub Form_Unload(Cancel As Integer)

The Unload event has the following argument.

Argument Description
Cancel The setting determines whether to unload the form. Setting Cancel to True (–1) prevents the form from being unloaded.

Remarks

You can place initialization code in a form's Load event procedure. For example, you can specify default settings for controls and initialize form-level variables.

You can't cancel the Load event.

In an Unload event procedure, you can include any form-level validation code you might need to close the form or save the data it contains to a file.

If Cancel is set to True for a form that is modal, you may not be able to return control to the rest of the application.