ACC: How to Use the LIKE Operator in Parameter Queries

ID: Q88671


The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97


SUMMARY

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

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: ] & "*"

    -or-

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

    NOTE: The Parameters dialog box has a display limit of 37 characters.


  3. 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 "D", type "D" (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 "d" anywhere in the field, type "d" (without the quotation marks) and begin the search.



REFERENCES

For more information about parameter queries, search the Help Index for "parameter query," or ask the Microsoft Access 97 Office Assistant.

Keywords : kbusage QryParm
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: March 10, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.