Unload Statement

Unloads a form.

Syntax

Unload frmVar

Comments

The Unload statement destroys the window which represents the visible part of the form on the screen. 

Before a form is unloaded, the OnQueryUnload event occurs, followed by the OnUnload event. Setting the pbCancel argument to True in either of these events prevents the form from being unloaded. For MDIForm objects, the following event procedures occur in the following order:

When a form is unloaded, all controls placed on the form at run-time are no longer accessible. Any run-time changes to those controls and their properties are lost when the form is reloaded. All changes to form properties are also lost. 

When a form is unloaded, only the displayed component is unloaded. The form object, its variables, and its procedures are still accessible until the form object is deleted.

The form object can be explicitly and completely destroyed by assigning Nothing to frmVar. If frmVar is a local variable, the form object will be destroyed when the procedure or event returns.

When using the Unload statement within the form you want to unload, use the Form internal variable.

You can call Unload statement on a form many times only the first will be processed.

Example

The first example unloads a form, frmMain. In the second example, a button event is set to unload the form containing the button, btnCancel. Here, the reference is to the Form object, Form, rather than to the name of the form variable.

Unload frmMain

btnCancel OnClick

{

 unload Form

}

See Also

AForm Class, Load Statement, OnInitialize Event (AForm), OnLoad Event (AForm), OnQueryUnload Event (AForm), OnTerminate Event (AForm), OnUnload Event (AForm),
Loading and Unloading Events