IT tutorials
 
Office
 

Microsoft Access 2010 : Working with Simple Criteria (part 2) - Creating Criteria Based on Multiple Conditions

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Product Key Free : Microsoft Office 2019 – Serial Number
12/8/2012 6:04:58 PM

Creating Criteria Based on Multiple Conditions

Sometimes you might want to create a query that contains two or more conditions. You would do this, for example, if you want only records in the state of California that had sales within a certain date range to appear in the output. The And condition is used to indicate that both of two conditions must be met for the row to be included in the resulting recordset. You can use the And condition in the same field or on multiple fields.

Use the And Condition on Multiple Fields

By placing criteria for multiple fields on the same line of the query grid, you create an And condition. This means that both conditions must be true for the records to appear in the result. An example of an And condition on two fields is State Field = ‘TX’ And Credit limit >=5000. Here’s how you create an And condition:

1.
Open the desired query in Design view.

2.
Select the cell on the Criteria row below the field that contains the first condition you want to enter.

3.
Type the first criterion you want to enter. For example, you can type Sales Representative as the criterion for Job Title.

4.
Select the cell on the Criteria row below the field that contains the second condition you want to apply.

5.
Type the second criterion you want to apply. Figure 3 shows USA as the criterion for the Country.

Figure 3. The design of a query with criteria for Job Title and Country.

6.
Click the Run button to run the query. Only rows that meet both conditions appear in the query result (see Figure 4).

Figure 4. The Result Includes All Sales Representatives in the USA.

 


Use the And Condition in a Single Field

In only a few situations would you use an And condition on the same field. This is because in most situations using the And condition on the same field would yield a recordset with no results. For example, the criteria State = TX and State = CA would yield no results because the state cannot be equal to both values at the same time. On the other hand, HireDate > 7/1/2001 and HireDate < 6/30/2002 would return all employees hired in that date range. Here’s how you would enter this sort of criteria:

1.
Open the desired query in Design view.

2.
Select the cell on the Criteria row below the field that contains the condition you want to add.

3.
Type the first criterion you want to add (for example, HireDate > 7/1/2001).

4.
Type the keyword And.

5.
Type the second criterion (for example, HireDate < 6/30/2002).

6.
Click the Run button. Access runs the query.

You need to make sure when you are adding the criteria to each field that you remain on the same row of the query grid.



Use Wildcards in a Query

You can use wildcards to select records that follow a pattern. However, you can use the wildcard characters only in Text or Date/Time fields. You use the * to substitute for multiple characters, and the ? to substitute for single characters. To practice using wildcards in a query, follow these steps:

1.
Open the desired query in Design view.

2.
Select the cell on the Criteria row below the field that contains the condition.

3.
Type the criteria, using a wildcard in the desired expression. In Figure 5, the expression Like Sales* is entered for the Job Title field. This expression returns all rows where the Job Title begins with Sales.

Figure 5. Example that contains Sales* as the Criteria for the Job Title.

4.
Click the Run button. The results of the query are shown in Figure 6, and show all the records where the contact title begins with Sales.

Figure 6. The result of running a query with criteria that contains the wildcard *.

Table 2 provides examples of how to use wildcards.

Table 2. Examples of Using Wildcards
ExpressionResults
Sm?thFinds Smith or Smyth.
L*ngFinds any record that starts with L and ends in ng.
*thFinds any record that ends in th (for example, 158th or Garth).
*on*Finds any record that has on anywhere in the field.
*/2000Finds all dates in 2000.
6/*/2000Finds all dates in June 2000.

Access displays the word Like in the criteria cell before a wildcard criteria. It is not necessary to type the word Like in the criteria cell before the criteria.



Use Comparison Operators in a Query

Sometimes you want to select records in a table that fall within a range of values. You can use comparison operators (=, <, >, <=, >=) to create criteria based on the comparison of the value contained in a field to a value that you specify in your criteria. Each record is evaluated, and only records that meet the condition are included in the recordset. To practice using comparison operators in your queries, follow these steps:

1.
Open the desired query in Design view.

2.
Select the cell on the Criteria row below the field for which you want to apply the condition.

3.
Type a comparison operator and the criteria you want the query to apply (for example, > 100).

4.
Click the Run button. The result of the query appears in Datasheet view.

Table 3 gives an example of comparison operators used for a field called Sales. It shows the operators, provides an example of each, and discusses the records that Access would include in the output.

Table 3. Comparison Operators Used to Compare Against a Field Called Sales
OperatorIndicatesExampleIncludes Records Where
>Greater than>7500Sales are greater than 7500
>=Greater than or equal to>=7500Sales are 7500 or more
<Less than<7500Sales are less than 7500
<=Less than or equal to<=7500Sales are 7500 or less
<>Does not equal<>7500Sales are not 7500
BetweenRange of valuesBetween 5000 and 7500Sales are between 5000 and 7500

You can use the word Not in place of the <> symbols.



Use the Or Condition on a Single Field

The Or condition states that either condition of two conditions should be met for the record to appear in the result set. You can use the Or condition on a single field or on more than one field. To practice using an Or condition on a single field, follow these steps:

1.
Open the desired query in Design view.

2.
Select the cell on the Criteria row below the field that contains the condition.

3.
Type the first criterion you want the query to apply. For example, you could type Sales Manager as criterion for the Job Title field.

4.
Select the cell below the current cell (this is the Or row).

5.
Type the second criterion you want the query to apply. For example you could type Sales Agent as criterion for the Job Title field (see Figure 7)
Figure 7. Using an Or condition on the Job Title field.

6.
Click the Run button. The result of this query is shown in Figure 8. Notice that the result contains all the sales managers, sales agents, sales representatives, and owners.



Figure 8. The result contains all the records that contain sales manager, sales agent, sales representative, or owner in the Job Title field.


Use the Or Condition on Multiple Fields

An alternative to using the Or condition on a single field is to use the Or condition to create criteria on multiple fields. An example is City equals Bellevue or Contact Title equals Sales Agent. These criteria would return all companies in Bellevue, regardless of the contact title, and all sales agents, regardless of the city. Here’s how you use the Or condition on multiple fields:

1.
Open the desired query in Design view.

2.
Select the cell on the Criteria row below the field for which you want to apply the first condition.

3.
Type the first criterion you want the query to apply (from the criteria mentioned in the intro to the steps).

4.
Select the cell in the Or row below the second field for which you want to apply the criterion.

5.
Type the second criterion you want the query to apply (see Figure 9).

Figure 9. Using the Or condition on multiple fields.

6.
Click the Run button. The result of this query is shown in Figure 10. Notice that the output contains all rows where the city is Bellevue or the contact title is sales agent.

Figure 10. The result contains the rows where the city is Bellevue or the job title is sales agent.

When you use two fields in an Or condition, you need to make sure the criteria are listed on two separate lines. If not, they will combine as an And condition.

You need to use the Or condition to find dates or numbers that fall outside a range (for example, before 6/1/2006 or after 1/1/2007).

You can use the word In and list the multiple criteria, separated by commas, in parentheses (for example, In (‘USA’, ‘France’, ‘Canada’)).

 
Others
 
- Microsoft Access 2010 : Working with Simple Criteria (part 1) - Using an Exact Match Query
- Microsoft Excel 2010 : Grouping Multiple Sets of Data
- Microsoft Excel 2010 : Consolidating Multiple Sets of Data into a Single Workbook
- Microsoft Word 2010 : Selecting Text Attributes (part 2)
- Microsoft Word 2010 : Selecting Text Attributes (part 1) - Choosing a Font, Selecting a Font Size, Applying Formatting Attributes
- Microsoft Project 2010 : Using Sorts and Auto-filters
- Microsoft Visio 2010 : Creating Rack Diagrams
- Microsoft Visio 2010 : Organizing Network Shapes in a Diagram
- Microsoft Outlook 2010 : How Outlook Stores Data
- Microsoft Outlook 2010 : Overview of Outlook (part 2) - Contact Management, Task Management, Tracking with the Outlook Journal, Organizing Your Thoughts with Notes
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us