Filtering Items Using Comparison and Logical Operators

Comparison Operators

Use the following comparison operators in filter strings using Microsoft Jet syntax or DAV Searching and Locating (DASL) syntax:

  • <

    Performs a less-than comparison.

  • Performs a greater-than comparison.

  • <=

    Performs a less-than-or-equal-to comparison.

  • =

    Performs a greater-than-or-equal-to comparison.

  • <>

    Performs a not-equal-to comparison.

  • =

    Performs a equal-to comparison.

Logical Operators

Use the logical operators And, Not, Or in filter strings in Jet or DASL syntax. The order of precedence of these operators, from the highest to the lowest, is: Not, And, Or. Use parentheses to indicate specific precedence in a filter. Logical operators are case-insensitive.

  • Not

    Performs a logical NOT on the condition. The following code retrieves all contacts whose first name is Jane and who don't work at Microsoft.

  criteria = _ "[FirstName] = 'Jane' And Not([CompanyName] = 'Microsoft')"
  • And

    Performs a logical AND on the condition. The following code retrieves all contacts who work at Microsoft and whose first name is Mary.

  criteria = _ "[FirstName] = 'Mary' And [CompanyName] = 'Microsoft'"
  • Or

    Performs a logical OR on the condition. The following code returns all contact items that have either a first name of Peter or Paul.

  criteria = "[FirstName] = 'Peter' Or [FirstName] = 'Paul'"

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.