Sorting Data in Access

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The key to sorting data in an Access database is to define a query that specifies the sort order. You can do this by setting the Sort field in the query design grid to Ascending or Descending, or by including an ORDER BY clause in the SQL statement. You can ensure that you always display sorted data in a form, report, or data access page by specifying a sorted query as the record source.

You can speed up sort and find operations by defining indexes on Access tables. An index can be based on a single field or on multiple fields. The index can enforce certain rules for a field or set of fields, such as whether the indexed field contains unique values, whether to ignore Null values, and whether the index includes the primary key for the table. The primary key is a special type of index that uniquely identifies each record in the table.

You can add an index to a table by using the table design view in Access, or create it programmatically, through ADO or DAO. For more information about indexes, see Chapter 14, "Working with the Data Access Components of an Office Solution," or search the Microsoft Access Help index for "indexes."