Form_Close

K

kenrav

After the user clicks the red X at the top of a form to close it, I'd like to
ask the user if he/she really wants to exit. I created a VbYesNo question in
the Form_Close event; Yes to continue closing and No to cancel. Question,
what code to put to keep the form from closing (inasmuch as we're already in
the Form_Close event?)
 
M

Marshall Barton

kenrav said:
After the user clicks the red X at the top of a form to close it, I'd like to
ask the user if he/she really wants to exit. I created a VbYesNo question in
the Form_Close event; Yes to continue closing and No to cancel. Question,
what code to put to keep the form from closing (inasmuch as we're already in
the Form_Close event?)


Use the form's Unload event with the Cancel argument:

If MsgBox("Close?", vbYesNo) = vbNo Then Cancel = True
 
D

Damon Heron

Put your code in the unload event.

for the No answer,
Cancel= true
exit sub

Damon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

form save code does not work 2
Form On exit event 3
Canceling a form events from firing 1
On Close 1
Current event firing on form closure ? 1
DoCmd.Quit in Form OnClose leads to error 2
Keep Focus 2
Form_Close 2

Top