Sort records (ADP)

Microsoft Office Access 2003

ShowSort records in a view, stored procedure, or in-line function

  1. In the Database window, click Queries Button image under Objects, click the view, stored procedure, or in-line function you want to open, and then click Design on the Database window toolbar.
  2. If you have not already, add to the Grid pane the columns or expressions that you want to sort by.

    If you don't want the columns or expressions to be part of the query results, remove them as output columns.

  3. In the Grid pane, locate the row containing the first data column or expression to sort by, and then in the Sort Type grid column, choose Ascending or Descending.

    Grid pane image

  4. If you want to sort by multiple columns or expressions, specify the sort order in the Sort Order column of the grid.

    For example, if you query an employee table, you can order the results by department (sort order = 1) and within each department by last name (sort order = 2).

Note  For a view and inline user-defined function, Microsoft Access automatically adds a TOP 100 PERCENT clause to the SQL statement.

ShowSort records in a table function

  • In the Database window, click Queries Button image under Objects, click the table function you want to open, and then click Design on the Database window toolbar.

    In the SQL text editor, enter a SELECT statement with an ORDER BY clause. For example:

    SELECT LastName, FirstName, Title FROM Employees ORDER BY Title, LastName

    In this example, you order the results by title (sort order = 1) and within each title by last name (sort order = 2).

ShowSort records by using an SQL statement in the RecordSource property of a form or report

  1. Open the form or report in Design view.
  2. Open the property sheet.

    ShowHow?

    1. Open a table, query, form, report, or data access page in Design view.
    2. Open the property sheet by doing one of the following:

      Form or report selector

      Callout 1 Form or report selector

      • On a data access page, click Select Page on the Edit menu.
      • On a table or query, click Properties Button image on the toolbar.
      • For a section on a form or report, double-click the section selector.

      Section selector

      Callout 1 Section selector

      • For a section on a data access page, double-click the section bar.

      Section bar in a data access page

      Callout 1 Section bar

      • To set properties of a query field, click the cell in the Field row, and then click Properties Button image on the toolbar.
      • To set properties of a query field list, click anywhere in the list, and then click Properties Button image on the toolbar.
      • To set properties for the body of a data access page, click above the first section, and then click Properties Button image on the toolbar.
      • To set properties for a control, click the control, and then click Properties Button image on the toolbar.
    3. In the property sheet, click the property you want to set, and then do one of the following:
      • If an arrow appears in the property box, click it and then select a value from the list.
      • Type a setting or expression in the property box.
      • If a Build button Button image appears next to the property box, click it to display a builder or list of builders.

    ShowTips

    • To get Help on any property in the property sheet, click the property and then press F1.

    • If you need more space to enter or edit a property setting, press SHIFT+F2 to open the Zoom box.

    Note  If the AllowDesignChanges property of a form is set to All Views, you can also set form properties in Form view and Datasheet view.

  3. Enter an SQL SELECT statement with an ORDER BY clause. For example:

    SELECT LastName, FirstName, Title FROM Employees ORDER BY Title, LastName

    In this example, you order the results by title (sort order = 1) and within each title by last name (sort order = 2).

    ShowTip

    To make it easier to type the SELECT statement, right-click the RecordSource property and click Zoom, or click the Build button Button image next to the RowSource property to open the Query Builder.

ShowSort records after they are retrieved from the database in Form or Datasheet view

ShowSort records locally in Form view or Datasheet view

  1. Click the field you want to use for sorting records. To sort records in a subform, click the field you want to sort.
  2. Click Sort Ascending Button image or Sort Descending Button image.

Notes

  • In a form, you can sort on only one field at a time; in a datasheet, you can select two or more adjacent columns at the same time, and then sort them. Access sorts records starting with the leftmost selected column.
  • When you insert new records or edit existing ones, the sort order is automatically removed. You can resort the records when you're done.

ShowSort records in a report

ShowSpecify a sort order

  1. Open the report in Design view.
  2. Click Sorting And Grouping Button image on the toolbar to display the Sorting And Grouping box.
  3. In the first row of the Field/Expression column, select a field name, or type an expression.

    The field or expression in the first row is the first sorting level (the largest set). The second row is the second sorting level, and so on.

    Note  When you fill in the Field/Expression column, Microsoft Access sets the Sort Order to Ascending.

Notes

  • You can sort on up to 10 fields or expressions in a report.

  • The Customer Labels report in the Northwind sample database sorts records by the values in three fields. To view this report, point to Sample Databases on the Help menu, click either Northwind Sample Database or Northwind Sample Access Project, and then open the Customer Labels report in Design view.

ShowReapply an inherited sort order

  1. Open the report in Design view, or if the report is already open, make sure it is selected.
  2. Click Properties Button image on the toolbar to display the report's property sheet.
  3. In the OrderByOn property box, click Yes to reapply it.

Note  If you specify a sort order in a report wizard or in the Sorting And Grouping dialog box in report Design view, it overrides the inherited sort order.

ShowSort records on a data access page

ShowSort records on a Page

You can sort data on a data access page, including data that's grouped. For grouped data access pages, you can sort the list of groups or the records within a group.

  1. Open a data access page in Page view.
  2. Do one of the following:
    • In an ungrouped page, click the field you want to use for sorting records.
    • In a grouped page, expand the group that you want to sort, and then click the field you want to sort records on.

      Note  When you sort records within a group, the sort order applies only to that group. It does not affect the order of records in other groups.

  3. Do one of the following:
    • To sort in ascending order, click Sort Ascending Button image.
    • To sort in descending order, click Sort Descending Button image.

ShowTip

If the records are displayed in tabular format, simply click the label of the field you want to sort records on. The records will display in ascending order. To sort records in descending order, click the label again.

Notes

  • When you close the data access page, you'll lose the sort order. You can sort the records again when you open the page.
  • The order in which numbers, text, and special characters are sorted depends on the database and your regional settings in Microsoft Windows Control Panel.
  • This procedure doesn't apply to a Microsoft Office PivotTable Component, Spreadsheet Component, or Chart Component. These features can be sorted independently from the rest of the data on the data access page, and may also support additional sorting capabilities. For more information, click Help Button image on the toolbar for the PivotTable list, spreadsheet, or chart, and then search for "sorting."

ShowChange the default sort order on a Page

  1. Open the data access page in Design view.
  2. Scroll to a section that belongs to the group for which you want to specify the sort order.
  3. Right-click the section bar, and then click Group Level Properties.
  4. In the DefaultSort property box, type the name of the field you want to sort on. If you want to sort on multiple names, separate each field name with a comma. If you want to sort in ascending or descending order, follow each name with a space and the keyword ASC or DESC, respectively. For example, type OrderDate DESC, OrderID ASC. If you don't specify the order, Microsoft Access sorts in ascending order.

Note  If the control you want to sort on is bound to an expression, you must type the alias of the control as displayed in its ControlSource property. For example, if the ControlSource property of the control you want to sort on is set to GroupOfExtendedPrice: ExtendedPrice, type GroupOfExtendedPrice in the DefaultSort property box.

ShowSort data in PivotTable or PivotChart view

ShowSort data in ascending or descending order

You can sort data that is displayed in natural or custom order in ascending or descending order.

  1. Open a datasheet or form in PivotTable view or PivotChart view.
  2. Do one of the following:

    ShowIn PivotTable view

    • To sort the data in a field based on the item labels, click the label of the field that contains the data you want to sort.

    • To sort the data in a field based on the summary values in a column, click a cell in the column that contains the values that you want to sort on.

    • To sort the data in a field based on subtotal or grand total values, click a subtotal or grand total value for the field that contains the data you want to sort.

    Note  If you click a grand total value in the bottom row, the columns will be sorted instead of the rows.

    ShowIn PivotChart view

    • To sort numeric data in a series, click the series or a series point within the series you want to sort.
    • To sort items in a field alphabetically, click the category field or series field, or click a category axis label.
  3. On the PivotTable or PivotChart toolbar, click Sort Ascending Button image or Sort Descending Button image.

Notes

  • To sort on multiple fields, start by sorting the innermost field first and work backward, sorting the outermost field last.

ShowSpecify a custom sort order in PivotTable view

  1. Open a datasheet or form in PivotTable view.
  2. Select the item you want to move.
  3. Drag the selected item and drop it over the item above which you want to place it.
  4. Repeat steps 2 and 3 until you have the items in the order you want.

Notes

  • To switch from ascending or descending sort to custom sort, click Sort Ascending Button image or Sort Descending Button image on the PivotTable toolbar so that the button is not selected.
  • If a field with custom sorting has a parent field, each parent member will display the lower-level members in custom order.

Note  The order in which numbers, text, and special characters are sorted depends on the source data and your regional settings in Microsoft Windows Control Panel.