-
How do I code my program to detect sudden app termination from the upper right "X" ?
-
Try using this code and see if it works for your situation.
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Select Case UnloadMode
Case vbFormControlMenu
MsgBox "The user chose the Close command from the Control menu on the form."
Case vbFormCode
MsgBox "The Unload statement is invoked from code."
Case vbAppWindows
MsgBox "The current Microsoft Windows operating environment session is ending."
Case vbAppTaskManager
MsgBox "The Microsoft Windows Task Manager is closing the application."
Case vbFormMDIForm
MsgBox "An MDI child form is closing because the MDI form is closing."
Case vbFormOwner
MsgBox "A form is closing because its owner is closing."
End Select
End Sub
The vbControlMenu is what was passed to the QueryUnload event when I clicked the "X" in the upper right hand corner and when I went to the control menu clicked close.
If you have an exit on your menu bar or a command button the vbFormCode will be passed in.
Is this what your looking for?
-
That was pretty neat.
Thanks.
To answer your question, what i was looking for was to ensure that if at anytime , if somewhere in my prgram the user closes the program using the "X" that my program will actually close properly and release it's influence on the system's resources.
Thanks for your help.
-
You can also put code in the Form_Unload event to clean up any open objects, etc.