On Close Event

  • Thread starter Thread starter Joe Williams
  • Start date Start date
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
 
You can disable the X button by set Close Button property to False in form
design view.

Hope it may help,
Suntisuk
 
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
 
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.
 
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.
 
Back
Top