|
The QueryUnload event is triggered when a form or application is closed by pressing the close button on the ControlBox. Setting Cancel to non-zero allows you to stop ActiveBar from releasing and closing the forms and controls that it contains. Although this event is fired before the form’s QueryUnload event, you must also set the Cancel value in the form’s QueryUnload event. You can do this by declaring a module level variable and setting the form’s QueryUnload Cancel argument to ActiveBar’s QueryUnload Cancel value. Note: This event only fires when the form or application is closed. If you unload the form through code, this event is not fired and you will only need to set the form’s QueryUnload Cancel value. Example 'Module level variable 'Used as flag to indicate when ActiveBar's QueryUnload event has fired Private m_ABQUnloadFired As Boolean 'Module level variable used to hold Cancel value when ActiveBar's QueryUnload event has fired Private m_ABQUnloadCancel As Integer Private Sub ActiveBar2_QueryUnload(Cancel As Integer) Dim rc As Long 'Get Cancel Value rc = MsgBox("Cancel form unload?", vbYesNo + vbQuestion, "ActiveBar's QueryUnload") If rc = vbYes Then Cancel = True '-1 **Stop Unloading** Else Cancel = False '0 **Resume Unloading** End If m_ABQUnloadFired = True m_ABQUnloadCancel = Cancel End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Dim rc As Long 'If ActiveBar's QueryUnload event fired then set Form_QueryUnload Cancel ActiveBar_QueryUnload Cancel value If m_ABQUnloadFired Then Cancel = m_ABQUnloadCancel 'Reset flag m_ABQUnloadFired = False Else rc = MsgBox("Cancel form unload?", vbYesNo + vbQuestion, "Form's QueryUnload") If rc = vbYes Then Cancel = True '-1 **Stop Unloading** Else Cancel = False '0 **Resume Unloading** End If End If End Sub
|