This example creates a new recordset that contains records from the Customer recordset in the Nwindex.mdb database, and then it copies the recordset contents to Sheet1. These records contain only data on customers located in New York. The example copies a new, sorted recordset to Microsoft Excel.
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.Filter = "[REGION] = 'NY'"
Set sortedSet = rs.OpenRecordset()
Sheets("Sheet1").Activate
ActiveCell.CopyFromRecordset sortedSet
sortedSet.Close
rs.Close
db.Close