Using the Sort property of a recordset, you can specify the order in which the records appear in an existing recordset. This eliminates the need to return to the data source, perhaps over a network, to get a new recordset of sorted data. Depending on the client's computer and size of the recordset, this may be more efficient than re-creating the recordset.


Note To use the Sort property with SQL Server you must use a client-side cursor. This is because, depending on the provider, a server-side cursor may or may not support sorting and SQL server does not.


To see a demonstration of how to sort records, click this icon.
      

When applying a sort, you can choose between the ASC and DESC keyword. To sort the records in ascending order, use ASC. To sort the records in descending order, use DESC.

The following example code sorts an existing recordset based on the LastName field of a recordset in ascending order:

rsStudents.Sort = "LastName ASC"
  

Disabling a Sort

In order to return a recordset to its original order, set the Sort property to an empty string. The following example code disables a sort:

rsStudents.Sort = ""