On Close Event

J

Joe Williams

I am trying to use an IF statement to check if a form is filled out
correctly. If not, a msgbox is displayed and the form should not be closed.

I can do it with a cmd button, but I am trying to code the IF statement in
the On close event of the form in case the user hits the X to close the form
instead of my command button or closes the form in some other way.

How do I tell the On Close event to cancel if a certain condition is not
met? Here is aircode of what is not working right now. (Doesn't work though,
the cancel = true statemetn does not stop the form from closing)

If me.txtbox <> "1" then
msgbox "You did not fill out the form correctly"
cancel = true
end if

Thanks

Joe
 
G

Guest

You can disable the X button by set Close Button property to False in form
design view.

Hope it may help,
Suntisuk
 
T

Todd Shillam

Try the form's BeforeUpdate event. During the OnClose event, I don't think
you can return--its like you've gone past the point of no return
so-to-speak.

Try DoCmd.CancelEvent instead of Cancel=True

Best regards,

Todd
 
P

Penguin

Try using the forms Unload property. If your conditions are not met
then cancel the unload by setting it to false. This should work if the
user tries to close the form anyway.
 
P

Penguin

Opps.... Cancel = True not false

Try using the forms Unload property. If your conditions are not met
then cancel the unload by setting it to false. This should work if the
user tries to close the form anyway.
 

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


Top