Private Sub Form_Queryunload (Cancel As Integer, UnloadMode As Integer) if unloadMode = vbformControlMenu Then Cancel = TrueEnd Sub
UNLOADMODE parameter returns the following value:
Constant Value Description VBFormControlMenu 0 Users Select "Off" instructions from the Controls menu on the form. VBFormcode 1 unload statement is called by code. VBAppWindows 2 The current Microsoft Windows operating environment session ends. The VBAPPTASKManager 3 Microsoft Windows Task Manager is closing the application. The VBFormmdiForm 4 MDI subscription is being closed because the MDI form is close. VBFormowner 5 is closing because the owner of the form is closed, so the form is also closed.