Apply a sort to the active datasheet, form or report (Access 2010+).
Syntax DoCmd.SetOrderBy(OrderBy, ControlName) Key OrderBy A string expression that includes the name of the field or fields on which to sort records and the optional ASC or DESC keywords. ControlName If provided and the active object is a form or report, the name of the control that corresponds to the subform or subreport that will be sorted. If empty and the active object is a form or report, the parent form or report is sorted.
To sort by more than one field name, separate the names with a comma.
By default the records are sorted in ascending order. To sort in descending order, add DESC to the end of the OrderBy argument
Example
'Sort the records by Last name and then first name:
DoCmd.SetOrderBy "LastName DESC, FirstName ASC"
“At school, new ideas are thrust at you every day. Out in the world, you'll have to find the inner motivation to search for new ideas on your own” ~ Bill Watterson
Related:
Select (SQL) - Retrieve data from one or more tables or queries.