cooldude4u2no
04-22-2004, 06:05 PM
How would you go about canceling a form unload? i have this msgbox appear asking if a user wants to save a file that has Yes No Cancel on it. When the user clicks cancel i dont want the form to unload. How do i go about doing that? thanks.
cooldude4u2no
webbone
04-22-2004, 06:10 PM
You can cancel unloading in the Query_Unload event. See the MSDN page for info: http://msdn.microsoft.com/library/en-us/vb98/html/vbevtqueryunload.asp
If your messagebox is in the Unload event you will need to move it.
Banjo
04-22-2004, 06:20 PM
To actually answer your question, the QueryUnload and Unload events both have a Cancel parameter. Set this to none zero to cancel the unload.
Do pay attention to webbone's link though. The distinction between the two events is important (although more so in MDI apps than SDI).
webbone
04-22-2004, 06:25 PM
*L* I learn something new everyday! I've always used QueryUnload and never even noticed that Unload has a cancel as well.
cooldude4u2no
04-22-2004, 06:30 PM
You can cancel unloading in the Query_Unload event. See the MSDN page for info: http://msdn.microsoft.com/library/en-us/vb98/html/vbevtqueryunload.asp
If your messagebox is in the Unload event you will need to move it.
Thanks! It worked... One step closer to completing my personal project...woohoo! Thanks again!
cooldude4u2no
04-22-2004, 06:33 PM
Ok another Question... How can i cancel the form from unloading when you press the cancel button on commondialog?
Banjo
04-22-2004, 06:35 PM
Set the CancelError property to true and wrap the call in an error handler.
cooldude4u2no
04-22-2004, 06:42 PM
Could you give me an example on how? Im clueless...
Banjo
04-22-2004, 06:44 PM
cdlg.CancelError = True
On Error Resume Next
cdlg.ShowOpen
If err.Number = 0 Then
' Do Stuff with cdlg.filename
Else
Cancel = True
End If
On Error Goto 0
Banjo
04-22-2004, 06:46 PM
Or alternatively:
cdlg.CancelError = True
On Error Goto CancelPressed
cdlg.ShowOpen
On Error Goto 0
' Do Stuff with cdlg.filename
Exit Sub
CancelPressed:
Cancel = True
End Sub
cooldude4u2no
04-22-2004, 08:31 PM
Or alternatively:
cdlg.CancelError = True
On Error Goto CancelPressed
cdlg.ShowOpen
On Error Goto 0
' Do Stuff with cdlg.filename
Exit Sub
CancelPressed:
Cancel = True
End Sub
Thanks man! That answered all of my questions...now it should all be smooth sailing...i hope :( lol...Thanks a ton.
Cooldude4u2no