Validate data in a control, if error remain in the control

clmarks

Registered User.
Local time
Today, 10:17
Joined
Jan 29, 2007
Messages
69
I'm working in Access 2003. I have a field for gender in a form. The user will enter either F or M, but cannot leave the field blank. I am running a procedure on the Exit event which gives an error message if the field is blank, but I can't stop the insertion point from moving on to the next field. I want it to stay in the Gender control. Am I going to have to do my validation when the next field gets the focus? If so, then I would have to perform that same validation on every field on the form. There must be an easy way.

How do I do this?

Thanks,

Cherry
 
You use the control's BEFORE UPDATE event to validate and then if it fails your validation you set

Cancel = True

and then they can't Exit.

If you do the validation in the On Exit then it is too late.
 
But, I would also use the Form's BEFORE UPDATE event to make sure that it is filled out because they might not actually enter that field. The control's Before Update event will not handle nulls - nothing added because nothing was changed. But you can check in the form's before update event to make sure that it is not null or empty string before you let the record save.
 

Users who are viewing this thread

Back
Top Bottom