As we note in "Initialize,
Load, and Activate Events", a form's QueryUnload event happens before its
Unload event. Both QueryUnload and Unload event procedures receive a Cancel parameter
that you can programmatically set to True to stop the form from unloading.
When you attempt to unload the main MDI form in an MDI application,
VB unloads all the open Child forms first. This means that the various Unload
and QueryUnload events have a special timing relationship in an MDI application.
When there is an attempt to unload the main MDI form, the order of the Unload
and QueryUnload events is as follows:
-
The MDI form's QueryUnload event
-
The QueryUnload event of each open Child form
-
The Unload event of each Child form
-
The Unload event of the MDI form
If Cancel is set to True within any of these event procedures,
the entire unloading process stops. If unloading is halted during any of the QueryUnload
event procedures, then none of the Unload events is triggered, and no form is
unloaded. If unloading is halted during any of the Unload event procedures, then
only forms whose Unload events happened before the one where the Cancel occurred
will unload.