|
|
How to Sort Records Before They're Retrieved from the Database 
There are two ways you can sort records before they are retrieved from the database: you can add an ORDER BY clause to either a stored procedure or an SQL statement.
Create a stored procedure with an ORDER BY clause
- In the Database window, click Stored Procedures under Objects, and then click New on the Database window toolbar.
A new stored procedure is created using skeleton SQL statements.
- If desired, replace
StoredProcedure1 in the first line with the unique name of the procedure. For example, you might use "MyProcedure" as the name:
Create Procedure MyProcedure
- Write the remaining procedure text in SQL and add an ORDER BY clause.
Tip If you don't know SQL syntax, you can create a view in the Query Designer and then convert the view to a stored procedure, as described in How to Work Around Table and View Sort Limitations.
Create an SQL statement with an ORDER BY clause
- In the Database window, click Forms or Reports under Objects, select a form or report, and then click Design on the Database window toolbar.
- Click the Properties button, click the Data tab, and then click the Build button to the right of the RecordSource property box.
- Add the columns or expressions that you want to sort by to the Grid pane.
- In the Output column of the grid, clear the check boxes for any columns or expressions that you don't want to be part of the query results.
- In the Sort Type grid column for each row containing a column or expression you want to sort by, click Ascending or Descending.
- If you are sorting by multiple columns or expressions, specify the sort order in the Sort Order column of the grid.
- On the View menu, point to Show Panes, and then click SQL. Note that Access creates the ORDER BY clause for you based on the information you enter in the Grid pane.
|