Question:
I have a message box that comes up to warn the user that they are terminating the application as it normally should be left running. I want to know how to stop that message if the machine is performing a shutdown. At the moment the event is fired every time. I have the event in the form.unload event of the main form so I can cancel the unload if the user does not want to close the application.
Answer:
Use the QueryUnload event, it has a parameter called unloadMode which tells you why the app is being shut down. The following are the possible values.
vbFormControlMenu: The user clicked the Close button on the Control menu on the form.
vbFormCode: The Unload statement is called from code.
vbAppWindows: The current Windows session is ending.
vbAppTaskManager: The Task Manager is closing the application.
vbFormMDIForm: An MDI child form is closing because the MDI parent form is closing.
vbFormOwner: A form is closing because its owner form is closing (owner is new to vb6, a form’s owner is specified as the Owner argument of the Show method).