MES via AccessMonster.com said:
I am trying to create a validation rule for a data-entry form field
(text field). I want this field to be required; therefore, my
validation rule should not allow null values or zero-strings.
Further, I would like to prevent the user from tabbing and continuing
on to the next field until this field is populated. How would I do
this? I tried using "IsNotNull" function, but that does not seem to
work.
Any help would be greatly appreciated. Thanks in advance.
There is no built-in "IsNotNull" function, only an "IsNull" function.
However, in a validation rule (in table design), you can specify a rule
"Is Not Null" (without the quotes). If you also set the field's Allow
Zero Length property to No, then you'll have prevented the user from
saving a record with this field empty. An alternative to the Validation
Rule approach would be to set the field's Required property to Yes (in
addition to forbidding zero-length strings); however, that won't let
you specify a specific message to display, the way the Validation Text
property does.
Be aware, though, that setting these properties doesn't keep the user
from tabbing through the field without entering anything. Unless the
user actually alters the value of the field, the rule is not applied
until the user attempts to save the record. You can use the control's
Exit event to check for an empty field and keep the focus in the
control, but you still have to ensure that the focus goes to that
control in the first place. That's why I prefer to do all my validation
when it comes time to save the record, in the form's BeforeUpdate event.
I don't care what the user puts in the various fields, or what path he
takes through them, until the record is about to be saved. Only then is
it necessary to make sure that the record is valid.