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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bringing up a Message Box when X Button is pressed

Status
Not open for further replies.

Gaff

Programmer
Dec 13, 2001
30
0
0
IE
I'm using an MDI form and when someone clicks on the X button on the parent form, i want a popup to comeup to confirm that they want to exit the application. I put the message box in the unload event of the form but even if someone selects no and they do not want to exit the application, i have an exit sub coded here, but the application still closes. Any ideas please. Thanks
 
i tried that but it still doesn't seem to work. The Exit Sub still seems to cause the whole thing to close. Here is my Sub:

Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim choice As String

choice = MsgBox("Are you sure you want to Exit the Application")

If choice = vbNo Then
Exit Sub
Else
End
End If
End Sub
 
Try this......


If UnloadMode = 1 then
choice = MsgBox("Are you sure you want to Exit the Application")

If choice = vbNo Then
Exit Sub
Else
End
End If
End if
Scott
Programmer Analyst
 
The Unload event has a variable "Cancel". If you set this to "1" or "True" before you "Exit Sub" it should cancel the Unload.

- Bill
 
Bill that worked a treat. Scott i didn't try your way because the other way was quicker. Thanks anyway though.
 
I could never get that to work either...the only way I could make it work was behind a button..

dont know why it wont work when a form unloads dvannoy@onyxes.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top