Sort Property Example

This example creates a new recordset from the Customer recordset in the Nwindex.mdb database, and then it copies the new recordset to Sheet1. The new recordset is sorted on the REGION field, in ascending order.

To create the Nwindex.mdb database, run the Microsoft Excel example for the CreateDatabase method.

Dim db As Database, rs As Recordset, sortedSet As Recordset
Set db = Workspaces(0).OpenDatabase(Application _
    .DefaultFilePath & "\NWINDEX.MDB")
Set rs = db.OpenRecordset("Customer", dbOpenDynaset)
rs.Sort = "[REGION]"
Set sortedSet = rs.OpenRecordset()
Sheets("Sheet1").Activate
ActiveCell.CopyFromRecordset sortedSet
sortedSet.Close
rs.Close
db.Close