Microsoft KB Archive/88671

= ACC: How to Use the LIKE Operator in Parameter Queries =

Article ID: 88671

Article Last Modified on 1/18/2007

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q88671



Novice: Requires knowledge of the user interface on single-user computers.



SUMMARY
This article shows you how to create a parameter query to search for all the records in a table that begin with, or that contain, a certain letter.



MORE INFORMATION
An easy way to search for records that begin with a certain letter is to create a parameter query that prompts for a character to search for. The LIKE operator can be used with the wildcard character (*) to accomplish this task. This example uses the Employees table in the sample database Northwind.mdb (or NWIND.MDB in Microsoft Access version 2.0 or earlier).

Method to Create Parameter Query Using the LIKE Operator

 * 1) Create a new query based on the Employees table.
 * 2) Type the following line in the Criteria box for the LastName field (or Last Name field in Microsoft Access 2.0 or earlier):

LIKE [Enter the first char to search by: ] & &quot;*&quot;

-or-

LIKE &quot;*&quot; & [Enter any char to search by: ] & &quot;*&quot;

NOTE: The Parameters dialog box has a display limit of 37 characters.
 * 1) When you run this query, you will be prompted with the message that you specified in the LIKE statement.

The first LIKE statement finds all the last names that begin with the letter that you type into the parameter prompt. For example, to find records where the last name starts with a &quot;D&quot;, type &quot;D&quot; (without the quotation marks) and begin the search.

The second LIKE statement finds all the last names that have the letter that you type into the parameter prompt anywhere in the field. For example, to find records where the last name has a &quot;d&quot; anywhere in the field, type &quot;d&quot; (without the quotation marks) and begin the search.

