Home Privacy Policy Feedback Link to us Site Map Forums

Access: Create a query that excludes records that contain a wildcard character in Access 2003/XP/2000/97


Question:  In Access 2003/XP/2000/97, I have a Comments field that has data with the asterisk (*) character in it. I'm trying to write a query that excludes all comments that contain an asterisk.

I tried using the LIKE Condition but it doesn't work since Access uses the asterisk as a wild card character.

Do you know how I can write a query that excludes all records that contain an asterisk wildcard character in the Comments field?

Answer:  We'll demonstrate how to do this with the example below.

If we had a Customers table that contained a Comments field populated as follows:


And we wanted to exclude the last two records from our query results since they contain an asterisk character in the Comments field. You could use the following condition:

Not Like '*[*]*'

By placing the wildcard character (in this case, asterisk) between square brackets, Access is able to search for the asterisk directly instead of treating it as a wildcard character.

[*]

The remainder of the NOT LIKE condition tells Access to look for all Comments that do not contain an asterisk character.

So if we create the following query:


We would return the following records:

As you can see, the last 2 records in the Customers table where filtered out since they contain the asterisk character in the Comments field.