ACC: Validation Rules Evaluate Expressions in Unexpected Ways

Last reviewed: May 28, 1997
Article ID: Q104972
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0

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 : GnlValid kbusage
Version : 1.0 1.1 2.0 7.0
Platform : WINDOWS
Hardware : X86
Issue type : kbprb
Resolution Type : Info_Provided


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.