Microsoft Office Online
Sign in to My Office Online (What's this?) | Sign in

 
 
Microsoft Office Access
Search
Search
 
Icon: Flag: (c) Microsoft
Get up to speed
 
 
 
Warning: You are viewing this page with an unsupported Web browser. This Web site works best with Microsoft Internet Explorer 6.0 or later, Firefox 1.5, or Netscape Navigator 8.0 or later. Learn more about supported browsers.

About designing a query (MDB)
 

Note  The information in this topic applies only to a Microsoft Access database (.mdb).

When you open a query in Design view (Design view: A window that shows the design of these database objects: tables, queries, forms, reports, macros, and data access pages. In Design view, you can create new database objects and modify the design of existing ones.), or open a form, report, or datasheet and show the Advanced Filter/Sort window (Advanced Filter/Sort window: A window in which you can create a filter from scratch. You enter criteria expressions in the filter design grid to restrict the records in the open form or datasheet to a subset of records that meet the criteria.), you see the design grid (design grid: The grid that you use to design a query or filter in query Design view or in the Advanced Filter/Sort window. For queries, this grid was formerly known as the QBE grid.), which you can use to make a variety of changes to get the query results you want.

Ways to modify a query in Design view

Callout 1 Add or remove tables, queries, and fields

Callout 2 Calculate amounts

Callout 3 Limit results using criteria

Callout 4 Sort records

Show Add or remove tables, queries, and fields

You can add a table or query if the data you need isn't in the query, or remove a table or query if you decide you don't need them. Once you add the tables or queries you need, you can then add the fields that you want to work with to the design grid, or remove them if you decide you don't need them.

Adding tables or queries and fields to the query design grid

Callout 1 A join line between field lists (field list: A window that lists all the fields in the underlying record source or database object, except in data access page Design view. In data access page Design view, it lists all the record sources and their fields in the underlying database.) tells Microsoft Access how the data in one table is related to the data in the other.

Callout 2 You drag a field from the field list to a column in the design grid to show the field in the query results.

For more information about adding and removing tables, queries, and fields, see the following topics:

Show Calculate amounts

You can add the values in a field or do other computations with the data by specifying the type of calculation to perform.

Defining calculations and groupings in the query design grid

Callout 1 Use an aggregate function (aggregate function: A function, such as Sum, Count, Avg, or Var, that you use to calculate totals.), such as Sum or Avg, to calculate one amount for all the records in each field in the design grid.

Callout 2 Use Group By to calculate separate amounts for groups of records in a field.

For more information about query calculations, see the following topics:

Show Limit results by using criteria

You can limit the records that you see in the query's results or the records that are included in a calculation by specifying criteria.

Specifying criteria in the query design grid

Callout 1 To limit the records in the query's results, enter criteria in one or more fields.

Callout 2 Use the Or row for alternative criteria in the same field.

Callout 3 Enter criteria for different fields. For example, for orders between 6/1/01 and 6/15/01 ...

Callout 4 ... calculate total order amounts, but display only those that are more than $100,000.

For more information about getting the results you want, see the following topics:

Show Sort records

You can sort the query's results by specifying a sort order in the design grid.

Specifying a sort order in the query design grid

Callout 1 If you specify a sort order for more than one field, Microsoft Access sorts the leftmost field first, so you should arrange the fields you want to sort from left to right in the design grid.

Callout 2 Sort by ascending or descending order, or remove a sort.

For more information on sorting, see the topic Sort records (MDB).

Show Use the asterisk in the query design grid

To include all fields from a table in a query, you can either select each field individually or use the asterisk (*) wildcard character. Selecting the asterisk has an advantage over selecting all the fields: When you use the asterisk, the query results automatically include any fields that are added to the underlying table or query after the query is created, and automatically exclude fields that are deleted.

When you use the asterisk, you must add fields along with the asterisk to the design grid (design grid: The grid that you use to design a query or filter in query Design view or in the Advanced Filter/Sort window. For queries, this grid was formerly known as the QBE grid.) before you can sort records or specify criteria for those fields.

When you drag more than one field at a time, Microsoft Access places each field in a separate column. If you drag the asterisk to the grid, Microsoft Access places the table or query name in one column and attaches a period and asterisk to the name (for example, Categories.*). After either operation, the datasheet looks the same.

If you type an asterisk in the Field row rather than dragging it, you must type the table name also. For example, type Customers.*.

The asterisk includes all fields from a table in a query

For more information, see the topic Use the asterisk (*) in the query design grid (MDB)

Show Considerations when designing or modifying queries in a multiuser environment

If you open a query to make design changes and someone else modifies the query design before you have finished, Microsoft Access displays a message telling you that the design has changed since you started working. You can either replace the new changes with your changes or save your version of the query with a different name. If others are using the query to view data while you're changing the design, they don't see the design changes until they close and reopen the query.

advertisement