
To get started with access search criteria, it's essential to understand the basics. Access search criteria is a powerful tool that allows you to filter and sort data based on specific conditions.
You can start by defining a search criteria set, which is a collection of criteria that you can use to filter data. For example, you can create a search criteria set to filter data based on a specific date range.
A search criteria set can contain up to 100 criteria, and each criterion can have up to 10 conditions. This allows you to create complex filters that meet your specific needs.
Access Search Criteria
To search for specific values in Access, you can use simple criteria like Contains, Does Not Contain, Begins with, and Ends with. These criteria are used in conjunction with the Like operator, which is used to search for patterns in text fields.
The Like operator is used with text fields, and it can be used with wildcards such as * to search for values anywhere in a field. For example, if you want to search for a value that begins with "x", you would use the Like operator with the syntax "Like "x*"".
Different field types require different delimiters, so you need to be aware of the type of field you're searching. For example, text fields require quotes around the search value, while number and currency fields do not.
For your interest: Dropbox Search Not Working
The Search Code
The Click event procedure for cmdFilter adds to the string strWhere by examining each unbound control in turn, and if not null, it adds to the string strWhere.
Different field types require different delimiters, so the code demonstrates searching each type of field. For Text type fields like City and MainName, quotes are added around the search value.
MainName is also a Text field, so again we add the quotes. This time we used the Like operator with the * wildcard, to show how to search for a value anywhere in a field.
LevelID is a Number type field, and as such, do not add the quote marks around values matched to a Number or Currency field.
IsCorporate is a Yes/No type field, and when searching, you need to give the user three choices: just Yes, just No, or Yes or No (all). The code tests if the value is -1 or 0, and adds to the Where string.
If this caught your attention, see: Azure Just in Time Access
EnteredOn is a Date/Time type field, so the code adds the # delimiter around the date value in the string, and formats it with the native JET format to avoid problems with international dates.
The code provides From and To boxes so the user can specify a date range. If the field contains a time component, your criteria must use "less than the next day" so the final date is included.
Here are the possible results when entering a date range:
The code tests its length less the 5 characters of the trailing " AND ", and shows a dialog if no criteria are found.
Field Types and Criteria
For Number, Currency, and AutoNumber fields, you can use criteria like "100" to exactly match a value, "Not 1000" to exclude a value, or "> 100" to include values larger than 100.
To include records that contain a range of values, you can use criteria like "Between 50 and 100". You can also use "In(20, 25, 30)" to include records that contain one of many specific values.
For Yes/No fields, values like "Yes", "True", "1", or "-1" are tested for a Yes value. Values like "No", "False", or "0" are tested for a No value. No value (null) is not tested.
You can use the word Like with some text in the criteria box, using wildcard characters like asterisks (*) or question marks (?). For example, "Like '*x*'" searches for all values that contain x. You can also use square brackets for a range of characters, like "[A-C]*", which searches for all items that begin with the letters A, B or C.
Here are some examples of text criteria:
Field Types and Criteria
Text fields can be searched using the Like operator, which is surrounded by double quotes. For example, to find all items that start with the letter C, you would use Like "C*".
You can use wildcard characters in text fields, such as the asterisk (*) to represent any character, or the question mark (?) to represent a single character. The question mark is useful for searching for partial matches, like in the example "Like "?ra???".
Here's an interesting read: Elasticsearch Search Text Field
Square brackets can be used to specify a range of characters, like in the example "Like "[A-C]*" which searches for all items that begin with the letters A, B, or C.
Text fields can also be searched using criteria like Contains, Does Not Contain, Begins with, and Ends with. For example, to find all values that contain a specific string, you would use the Contains operator, like "Like "*x*"".
Here are some common text criteria operators:
You can also use the Len() function to search for text fields of a certain length. For example, to find all items that are greater than 7 characters, you would use Len([Item]) > "7".
Field Types and Criteria
When working with dates, it's essential to use the correct criteria. For example, you can use "Between" to search for dates that fall between two dates, like this: Between "#mm/dd/yy#" and "#mm/dd/yy#".
You can also use "Before" to search for dates before a certain date, like <#mm/dd/yy#. This is useful for finding records that occurred before a specific date. For instance, if you want to find all records from last year, you can use <#01/01/yyyy#.
Another useful criteria is "After", which searches for dates after a certain date, like >#mm/dd/yy#. This is handy for finding records that occurred after a specific date. For example, if you want to find all records from this year, you can use >#01/01/yyyy#.
You can also use "Today" to search for all records containing today's date, like =Date(). This is useful for finding records that were created or updated on the current day.
If you need to find records from a certain number of days ago, you can use "Days Before Today", like <=Date()-x. This is useful for finding records that were created or updated within a specific time frame. For instance, if you want to find all records from the past week, you can use <=Date()-7.
You can also use "Is Null" to include records that do not contain any attachments, and "Is Not Null" to include records that contain attachments. This is useful for finding records with or without specific data.
Lookup fields can be used to search for values in an existing data source, or to display a list of values specified when the Lookup field is created. If the Lookup field is based on a list of specified values, you can use the same criteria as for other text fields.
On a similar theme: Gmail Search for Not Important
However, if the Lookup field is based on values from an existing data source, you need to use criteria that work for the data type of the foreign key, rather than the data type of the data being looked up. For example, if the foreign key is of the Number data type, you can use >2 to search for values greater than 2.
To determine the data type of the foreign key, you can inspect the source table in Design view. To do this, locate the source table in the Navigation Pane, open it in Design view, and look at the Data Type column of the table design grid.
If the multivalued field stores a list of numbers, you can use criteria like >5 AND finding records that meet complex criteria.
Here are some examples of valid criteria for different field types:
Simple Search Criteria
Simple search criteria can be a bit tricky, but don't worry, I've got you covered. The good news is that most data types have simple criteria that you can use to search for specific values.
To start, let's look at the basics. For all data types, you can use the following criteria: Equals, Does Not Equal, Null, and Not Null. These are pretty self-explanatory, but just to clarify, Equals searches for values that are exactly the same as the one you're looking for, while Does Not Equal searches for all values except those that are exactly the same.
Here's a quick rundown of these criteria:
Now, let's move on to text-specific criteria. These are a bit more nuanced, but still pretty straightforward. For text, you can use Contains, Does Not Contain, Begins with, Ends with, Comes After, and Comes Before.
For example, if you're looking for values that contain a specific word, you can use the Contains criteria and write it like "*x*". This will search for all values that have the word "x" somewhere in them. If you're looking for values that don't contain a specific word, you can use the Does Not Contain criteria and write it like "Not like "*x*"".
Here's a quick rundown of these text-specific criteria:
Field Types
When working with search criteria, it's essential to understand how different field types are evaluated. Let's start with Number fields, which can be exactly matched with a value, such as 100. This is as simple as entering the value in the Criteria row.
For Currency fields, the criteria are evaluated similarly to Number fields. However, AutoNumber fields require a specific approach, as they can't be exactly matched with a value.
If you need to include records that contain a value smaller than a certain value, you can use the "return records where the unit price is less than $100. You can also use the "<=" operator to include records where the unit price is less than or equal to $100.
For Yes/No fields, values entered in the Criteria row are evaluated as follows:
Yes/No Fields
Yes/No fields can be a bit tricky to understand, but don't worry, I've got you covered. They're used to indicate whether something is true or false, like a customer's account being active or not.
A value of "Yes" or "True" is equivalent to 1 or -1, which is converted to "True" in the Criteria row. This means you can enter either of these values and it will be treated as a Yes value.
Entering "No" or "False" is equivalent to 0, which is converted to "False" in the Criteria row. This means you can enter either of these values and it will be treated as a No value.
If you leave the field blank (null), it won't be tested. This can be useful if you want to exclude records with missing data from your query.
Recommended read: Onedrive No Access Permissions to the Item

Any number other than 1, -1, or 0 will result in no records being returned if it's the only criteria value in the field. This can be frustrating if you're not expecting it, but it makes sense when you think about it.
Any character string other than "Yes", "No", "True", or "False" will cause a Data type mismatch error and prevent your query from running. This is a good reminder to double-check your data before running a query.
Here's a quick reference table to help you remember the rules:
Other Fields
Attachments are a special case when it comes to criteria. To include records that do not contain any attachments, simply type "Is Null" in the Criteria row. This will return records where no attachments are present.
To include records that contain attachments, type "Is Not Null" in the Criteria row. This will return records where attachments are present.
Lookup fields are another type of field that can be tricky to work with. If you have a Lookup field based on a list of specified values, valid criteria are the same as for other text fields. For example, you can use "20 or 25" to return records where the value is either $20 or $25.
Broaden your view: How to Make a Search Bar Html
If you have a Lookup field based on values from an existing data source, the criteria you can use depend on the data type of the foreign key. For example, if the foreign key is of the Number data type, you can use criteria like ">2" to return records where the value is greater than 2.
To determine the data type of the foreign key, you can inspect the source table in Design view. To do this, locate the source table in the Navigation Pane, open it in Design view, and look at the Data Type column of the table design grid.
Here are some examples of criteria you can use with Lookup fields based on values from an existing data source:
Note that the criteria you use will depend on the data type of the foreign key, so be sure to check the source table in Design view to determine the correct data type.
Access 2013 Query Reference
In Access 2013, queries are the backbone of data retrieval and manipulation. You can create queries using the Query Wizard or by writing SQL code directly.
The Query Wizard helps you create a query by guiding you through a series of steps, making it easier to create a query, especially for beginners.
You can specify search criteria in the Query Wizard by using the "Criteria" box, where you can enter specific values or use operators like "Greater Than" or "Less Than".
The "Criteria" box is also where you can use wildcards, such as an asterisk (*) to match any characters.
For example, if you want to find all customers whose names start with "J", you can enter "J*" in the "Criteria" box.
You can also use the "In" operator to search for values that are in a list, like finding all customers who are in a specific city.
The "Like" operator is another useful tool for searching for values that match a pattern, such as finding all customers whose names end with "son".
Frequently Asked Questions
What are the 5 types of queries in Access?
There are five main types of queries in Access: Select, Action, Parameter, Crosstab, and SQL queries. Each type serves a unique purpose in data retrieval and manipulation, making Access a powerful database management tool.
Featured Images: pexels.com


