ADO Sort Property

Home | About me | EXCEL VB Programming (XL97-2003) | ACCESS Programming | EXCEL VB.Net Programming | EXCEL Spreadsheet Functions Material Management  |  Guestbook
 

ADO Sort Property

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.

Note: This property can only be used if the CursorLocation property is set to adUseClient.

Note: If you set this property to an empty string (objRecordset.Sort="") it will reset the records to their original order.

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.

Syntax

objRecordset.Sort

Example

objRecordset.Sort="CompanyName,ContactName"

or
objRecordset.Sort="CompanyName DESC,ContactName"
or
objRecordset.Sort="CompanyName,ContactName,[Ship Address]"
or
objRecordset.Sort = "" 

Explanation:
You can remove a sort by setting this property equal to the empty string "".