k, this should be a fairly easy question 2 answer....... how can i display a msgbox when the users presses X to close the form
i have tried Query_unload and Form_unload but none where successful
Printable View
k, this should be a fairly easy question 2 answer....... how can i display a msgbox when the users presses X to close the form
i have tried Query_unload and Form_unload but none where successful
VB Code:
Private Sub Form_Unload(Cancel As Integer) Dim intReply As Integer intReply = MsgBox("Do you really want to quit?", vbQuestion + vbYesNo, "Quit?") If intReply = vbNo Then Cancel = True End Sub
Both events you mentioned are called when the user close the form. Try this code:
VB Code:
Private Sub Form_Unload(Cancel As Integer) If MsgBox("Do you really want to close this window?", vbYesNo) = vbNo Then Cancel = True End If End Sub
You might be better off putting the code in the QueryUnload event.
Use the QueryUnload event and check the UnloadMode parameter to check how the form is being closed.
VB Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Dim strMess As String Select Case UnloadMode Case vbFormControlMenu strMess = "The user chose the Close command from the Control menu on the form." Case vbFormCode strMess = "The Unload statement is invoked from code." Case vbAppWindows strMess = "The current Microsoft Windows operating environment session is ending." Case vbAppTaskManager strMess = "The Microsoft Windows Task Manager is closing the application." Case vbFormMDIForm strMess = "An MDI child form is closing because the MDI form is closing." Case vbFormOwner strMess = "A form is closing because its owner is closing." End Select MsgBox strMess End Sub
thanks!