Microsoft KB Archive/209674

= ACC2000: How to Return Case-Sensitive Matches in Queries =

Article ID: 209674

Article Last Modified on 7/15/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



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).



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.



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
 Start Microsoft Access, and then create a new blank database. 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.  Add the following records to the tblNameList table:   FirstName     LastName -    --   Andrew        Maclean Nancy        Macleod Zareda       van Helsing andrew       MacLean nancy        MacLeod zareda       Van Helsing  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")

 Run the query. Note that you have selected only the records that contain first names with an initial lowercase letter.</ol>

Method 2: Find Text With a Lowercase Letter in Any Position Using the StrComp Function
<ol> If you have not already done so, create the test database using steps 1 through 3 in Method 1.</li> 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

</li> Run the query. Note that the query returns the same results as in Method 1.</li> 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."</li></ol>

<div class="references_section">