


Purpose
Expression: Like "pattern"
In an expression, you can use the Like operator to compare a field value to a string expression. For example, if
you type Like "C*" in the Criteria row of the QBE grid, the query returns all
field values beginning with the letter C. In a parameter query, you can prompt
the user for a pattern to search for. Suppose you type the following expression
in the Criteria row of the QBE grid:
You can also use Like in an expression as a setting for the ValidationRule property or as a macro
condition. The following example returns data that begins with the letter P
followed by any letter between A and F and three digits:
In Access Basic, if expression matches pattern, result is True (-1); if there is no match, result is False (0); and if either expression or pattern is a Null, result is also a Null. The case sensitivity and character sort order of the Like operator depend on the setting of the Option Compare statement. However, if
the module doesn't contain an Option Compare statement, the default
string-comparison method is Binary.
Like Operator
| Kind of match
| Pattern
| Match (returns True)
| No match (returns False)
|
| Multiple characters
| "a*a"
| "aa", "aBa", "aBBBa"
| "aBC"
|
|
| "*ab*"
| "abc", "AABB", "Xab"
| "aZb", "bac"
|
| Special character
| "a[*]a"
| "a*a"
| "aaa"
|
| Multiple characters
| "ab*"
| "abcdefg", "abc"
| "cab", "aab"
|
| Single character
| "a?a"
| "aaa", "a3a", "aBa"
| "aBBBa"
|
| Single digit
| "a#a"
| "a0a", "a1a", "a2a"
| "aaa", "a10a"
|
| Range of characters
| "[a-z]"
| "f", "p", "j"
| "2", "&"
|
| Outside a range
| "[!a-z]"
| "9", "&", "%"
| "b", "a"
|
| Not a digit
| "[!0-9]"
| "A", "a", "&", "~"
| "0", "1", "9"
|
| Combined
| "a[!b-m]#"
| "An9", "az0", "a99"
| "abc", "aj0"
|