Trap user in form

RichO

Registered Yoozer
Local time
Today, 06:18
Joined
Jan 14, 2004
Messages
1,036
I know this topic has been covered over and over but I've searched and searched and can't find my answer. I did find one post with a link to a possible answer but the link was broken.

My form has a required field. When a user attempts to X out of the form I have code in the Before Update event that checks this field and if it is blank:

MsgBox "Payment Terms must be filled in before closing the form"
Me.PaymentTerms.SetFocus
Cancel = True


The message box appears, but then the

You can't save this record at this time...blah blah blah.....

dialog appears and then the form closes.

How can I prevent the user from closing the form if this field is blank? It seems like once the X is clicked there is no turning back. I realize that I could remove the close button (X) from the form and use a command button instead but this may only mess up the users who have been using this DB for years. Is there any way to go backward once the close button has been clicked?

Thanks for your help.
 
Rich,
Have you looked into using a message box with "YES" "NO" "RETRY"????? And tie you "Retry" to Cancel = False........ Just a thought.
 
If they X out, you have to use the ON UNLOAD event of the form to set the Cancel = True which will then cancel the closing of the form and application.
 
A user can allways Ctl-Alt-Delete out. You can remove the control box and the "X" or cancel the unload but if the user really wants out then you cannot really stop them.

Maybe its better to set the unload event to use Me.Undo and not save the record. You can then alert the calling form/procedure if there is one to say the user canceled the operation.

:)
 
That's understandable in extreme situations but in this case there are a few people who occasionally forget to fill in that field and they just need to be reminded that they made the mistake.

Thanks
 

Users who are viewing this thread

Back
Top Bottom