ADODB Object
 
Syntax
 
string = recordsetobject.Sort
recordsetobject.Sort = string
 
Description
Sets or returns a string value that is a comma-delineated list of the names of which fields in the Recordset to sort.After each name, you can optionally add a blank space and the keywords ASC or DESC to designate the sort direction.
 
The Sort property sets or returns a string value that provides the names of the fields in the Recordset that you wish sorted. Each name must be separated by a delimiter comma and the entire string must be enclosed within a pair of double quotes. If the field name contains blank spaces, you need to enclose it within a pair of square brackets.
 
You also have the option of specifying that the sort be in ascending or descending order for each individual field. You can declare the sort order by placing a blank space followed by either the keyword ASC, for an ascending sort, or DESC, for a descending sort, directly after the field name, but before the delimiter comma. The default is to sort in ascending order. Therefore, if you want an ascending sort, you could skip including the keyword ASC.
 
The CursorLocation property will need to be set to adUseClient.
 
When you are using a client-side cursor, the ADO Cursor Engine will automatically create a temporary index for the sort rather than physically rearranging the data. This makes the sort more efficient. You can also create your own temporary index by setting the Optimize property of the Properties Collection of the Field object to True.
 
If you are using a server-side cursor, some providers may not support this property.
See Also
Example
 
objRecordset.Sort = "LastName, Birthdate"
 
 
objRecordset.Sort = "LastName DESC, FirstName DESC"
 
 
objRecordset.Sort = ""
 
Explanation:
 
You can remove a sort by setting this property equal to the empty string "".