Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop Form Closing 1

Status
Not open for further replies.

sha76

Programmer
Sep 2, 2002
5,085
GB
Hi,

Is there any code I can put in the unload event (or somewhere else) to keep a form open if the user chooses to from a message box?
I want to avoid disabling the close button & putting in my own as the form's in danger of getting a bit overcrowded!

Thanks for your help,

Sharon
 
Are you searching for this ?

Private Sub Form_Unload(Cancel As Integer)
Dim Result As VbMsgBoxResult

Result = MsgBox("Do you really want to close this window ?", vbYesNo, "Quit")

Cancel = Result = vbNo
End Sub
 
This makes for harder error checking, but less code...

This is how i prafer to do it...
Though both should work equily well...



Private Sub Form_Unload(Cancel As Integer)
if msgbox("Do you want to close this form?", vbyesno) = vbyes then cancel = true
End Sub junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Why so much complications ?

Private Sub Form_Unload(Cancel As Integer)
Cancel = vbNo = MsgBox("Do you really want to close this window ?", vbYesNo, "Quit")
End Sub
 
There ya go, even less then mine...

I like it when people out-program me... makes me work harder:) Thank you.

junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top