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 Return Case-Sensitive Matches in Queries


View products that this article applies to.

This article was previously published under Q209674
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies only to a Microsoft Access database (.mdb).

↑ Back to the top


Summary

You can use the Asc() function or the StrComp() function to have Microsoft Access differentiate between case-sensitive text strings. When you use the Asc() function in a select query, Access can locate an exact, case-sensitive match using the first letter of a text string. The StrComp() function can perform a case-sensitive match for the whole string.

Both of these functions can be useful in checking for names in a database that are supposed to be uppercase or proper case, but which have been entered incorrectly.

↑ Back to the top


More information

To find all the records in a field that contain lowercase text rather than uppercase text for the first character, use either of the following methods.

Method 1: Find Text With an Initial Lowercase Letter Using the Asc() Function

  1. Start Microsoft Access, and then create a new blank database.
  2. Create a new table with the following field:
    Field Name: FirstName
    Data Type: Text
    Field Size: 50

    Field Name: LastName
    Data Type: Text
    Field Size: 50
    Save the table as tblNameList. When you are prompted to create a key field, click No.
  3. Add the following records to the tblNameList table:
       FirstName     LastName
       ---------     ----------
       Andrew        Maclean
       Nancy         Macleod
       Zareda        van Helsing
       andrew        MacLean
       nancy         MacLeod
       zareda        Van Helsing
    					
  4. Create a new query based on the tblNameList table, and then enter the following data in the query grid:
    Field: FirstName
    Table: tblNameList
    Show: True

    Field: LastName
    Table: tblNameList
    Show: True

    Field: Asc([FirstName])
    Show: False
    Criteria: >=Asc("a") And <=Asc("z")
  5. Run the query. Note that you have selected only the records that contain first names with an initial lowercase letter.

Method 2: Find Text With a Lowercase Letter in Any Position Using the StrComp() Function

  1. If you have not already done so, create the test database using steps 1 through 3 in Method 1.
  2. Create a new query based on the tblNameList table, and then enter the following data in the query grid:
    Field: StrComp([FirstName],"a",0)
    Show: False
    Criteria: 1

    Field: FirstName
    Table: tblNameList
    Show: True

    Field: LastName
    Table: tblNameList
    Show: True
  3. Run the query. Note that the query returns the same results as in Method 1.
  4. Open the query in Design View, and then change the Field parameters in the first column of the query grid to:
    Field: StrComp([LastName],"Mack",0)
    Run the query. Note that the query returns "Maclean" and "Macleod," but not "MacLean" and "MacLeod." The records for "van Helsing" are also selected because the criteria you entered for the StrComp() function returns any binary values that are greater than the search criteria "Mack."

↑ Back to the top


References

For more information about the Asc() function, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type asc function in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more information about the StrComp() function, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type strcomp function in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB209674, kbusage, kbinfo, kbhowto

↑ Back to the top

Article Info
Article ID : 209674
Revision : 3
Created on : 7/15/2004
Published on : 7/15/2004
Exists online : False
Views : 298