cancel form_close

hbrems

has no clue...
Local time
Today, 12:43
Joined
Nov 2, 2006
Messages
181
I have the following code for when a user closes a form

Code:
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.
 
Use the UnLoad event rather than the Close event and set Cancel = True to stop the form from closing.
 
Yep it works. Thanks man.
 
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?
 
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
 
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?
 

Users who are viewing this thread

Back
Top Bottom