hbrems
11-08-2007, 09:00 AM
I have the following code for when a user closes a form
Private Sub Form_Close()
vconfirm = MsgBox("Are you sure you want to quit", vbYesNo, "IT problemlog")
Select Case vconfirm
Case vbYes
'form will close
Case vbNo
'don't close the form
End Select
End Sub
How can I cancel the close event when the user selects no?
Kind regards,
Hans B.
RuralGuy
11-08-2007, 09:26 AM
Use the UnLoad event rather than the Close event and set Cancel = True to stop the form from closing.
hbrems
11-09-2007, 02:21 AM
Yep it works. Thanks man.
RuralGuy
11-09-2007, 02:27 AM
You're very welcome. Thanks for posting back with your success.
Can you use this to prevent someone from Closing the entire instance of Access?
boblarson
12-27-2007, 09:04 AM
Yes, if you cancel the form's unload event Access will not close. The only way you can't get around is if they use Ctl+Alt+Del
ilse20
04-16-2010, 02:27 AM
i have a bit the same problem. I want to have that when you press the close button that you get a msgbox which asks if you want to quit without saving.
it works when i put it in form_unload. but i have also buttons on the form that closes the form when you have clicked on it.
it's a form where you have to choose a type and then when you click on a button it saves it in the table and closes the form. but if i put that code in form_unload it asks if you want to close without saving.
but when i put it in form_close it doesn't work.
i have already a cancel button on my form but i also want to have an event for the close(X) button. in case the users clicks on it by accident
is there a way to do this?