ACC: Validation Rules Evaluate Expressions in Unexpected Ways (104972)
The information in this article applies to:
- Microsoft Access 1.0
- Microsoft Access 1.1
- Microsoft Access 2.0
- Microsoft Access for Windows 95 7.0
This article was previously published under Q104972
Moderate: Requires basic macro, coding, and interoperability skills.
SYMPTOMS
Microsoft Access evaluates expressions with logical operators differently
than you expect. For example, if you enter zero in a field with the
validation rule set to "=true and not true," you may receive the following
error message:
The value you entered is prohibited by the validation rule set for
this field.
CAUSE
Microsoft Access evaluates expressions in parts, and compares each part to
the value in the field being validated. The expression "=true and not true"
is evaluated as:
Field=True AND Field<>True
This results in the error message if you enter zero in the field because
the validation fails.
RESOLUTION
Use parentheses in the expression to change the way the expression is
evaluated. The correct syntax for the example above is:
=(True AND NOT True)
Microsoft Access will interpret this expression as:
Field=(True AND NOT True)
Zero is an acceptable value for a field with the above validation rule.
Modification Type: | Major | Last Reviewed: | 5/6/2003 |
---|
Keywords: | kbprb kbusage KB104972 |
---|
|