ACC: Validation Rules Evaluate Expressions in Unexpected Ways

ID: Q104972


The information in this article applies to:


SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

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.


MORE INFORMATION

Steps to Reproduce Behavior


  1. Open a new, blank form in Design view.


  2. Add a text box with the following validation rule to the form:
    
          Text box: Field1
             Validation rule: =True and not True 


  3. View the form in Form view.


  4. Enter a zero in the text box, and then press ENTER. Note that you receive the error message mentioned earlier in this article.


Additional query words: boolean bitwise math


Keywords          : kbusage GnlValid 
Version           : 1.0 1.1 2.0 7.0
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: March 27, 1999