Note The information in this topic applies only to a Microsoft Access project (.adp).
You can search for patterns within data columns or expressions by using wildcard characters. For example, you can search for all employees whose last names begin with "Mac" or end with "son."
You can use wildcard characters to search any columns that can be treated as text strings. Columns with the data type character can always be treated as text strings; those with the datetime data type can be treated as text strings.
To search for patterns, use the LIKE operator, and then substitute wildcard characters for one or more characters in the search string. You can use either of the following wildcard characters:
|% (percent symbol)
||Zero or more characters in that position
||One character at that position
For example, to search for all names beginning with "Mac," you could specify the search condition
. To find names such as "Jan," "Jen," and "Jon," you could specify the search condition
Searching for Characters Used as Wildcard Characters
In some cases, you might need to search for a string that contains one of the characters used as a wildcard character. For example, in a
table you might want to find all the publications that contain the string "10%" as part of the title. Because "%" is part of the string you are searching for, you must specify that you mean it as a literal string and not a wildcard character.
To search for characters that can be interpreted as wildcard characters, you can specify an escape character. Place the escape character immediately in front of the "%" or "_" character that you mean literally. To specify the escape character, include an ESCAPE clause immediately after the LIKE search criterion. You can do this in either the Criteria column of the Grid pane or in the SQL pane.
For example, imagine that you want to find all titles that contain the string "10%". Suppose you want to define the character "#" as an escape character, which allows you to include "#" in front of the "%" character that is meant literally. You can enter this in the Grid pane:
LIKE '%10#%%' ESCAPE '#'
The resulting WHERE clause in the SQL statement looks like this:
WHERE title LIKE '%10#%%' ESCAPE '#'
Note You can define an escape character only in the SQL pane.
Searching Datetime Columns
When working with a datetime data type column, you can search any portion of the date or time, including text abbreviations of the month and complete years.
For example, you can use the following LIKE clause to search for all rows in which the date falls within 1994:
The following searches for all rows in which the date falls within the month of January, regardless of year:
Examples of Wildcard Searches
The following examples illustrate the use of wildcard characters.
|Finds values beginning with "Mac"
|Finds values starting with "J" and ending with "n"
|Finds values ending with "son"
|Finds values with "sam" anywhere in the string
|Finds values in a datetime column that fall in the month of March, regardless of year
01 Mar 1992
|Finds values in a datetime column for the year 1994.
01 Jan 1994
|Finds values with exactly four characters, the first three being "Mac"
|Finds values with exactly four characters, the last three being "dam"
|Finds values containing "s" and "n" at the end of the value, with any one character between them and any number of characters in front of them