Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Use the LIKE Operator in Parameter Queries


View products that this article applies to.

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.

↑ Back to the top


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. You can use the LIKE operator with the wildcard character (*) to accomplish this task. This example uses the Employees table in the sample database Northwind.mdb.

Method to Create Parameter Query Using the LIKE Operator

  1. Create a new query based on the Employees table.
  2. Drag LastName to the Field row and then type the following line in the Criteria row for the LastName field:
    LIKE [Enter the first char to search by: ] & "*"
    -or-
    LIKE "*" & [Enter any char to search by: ] & "*"
    NOTE: The Parameters dialog box is a fixed width so all the characters that you type may not display.
  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 "L", type L 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 "L" anywhere in the field, type L and begin the search.

↑ Back to the top


References

For more information about parameter queries, click Microsoft Access Help on the Help menu, type what is a parameter query and when would you use one in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB209823, kbhowto

↑ Back to the top

Article Info
Article ID : 209823
Revision : 2
Created on : 7/15/2004
Published on : 7/15/2004
Exists online : False
Views : 392