Canceling Form Unload ***Resolved***
Would I use the following code to prevent a form from unloading when the user click the red 'X' in the upper right hand corner of the form:
VB Code:
Private Sub Form_Unload(Cancel As Integer)
Cancel = True
Me.Hide
End Sub
Will this do the trick or should I use the Query_Unload Event?
Thanks
Re: Canceling Form Unload
Both will play the game...
QueryUnload is executed first
and Unload is executed after it ...
Re: Canceling Form Unload
Well in your case you should use the QueryUnload event since you only want to hide the form if someone clicks the X button. But if someone is shuting down Windows or you want to end the application through code you want to unload the form so your application ends properly. You can only test why your form is being unloaded in the QueryUnload event.
VB Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = vbFormControlMenu Then
'the X has been clicked or the user has pressed Alt+F4
Cancel = True
Me.Hide
End If
End Sub
Re: Canceling Form Unload
Joacim,
Thanks again!!!!
Mark