This example creates two worksheets to display the lists of data from the COMPANY and CUSTMR_ID fields in the filtered Customer recordset of the Nwindex.mdb database.
To create the Nwindex.mdb database, run the Microsoft Excel example for the CreateDatabase method.
Dim db As Database
Dim rs1 As Recordset, rs2 As Recordset
Set db = Workspaces(0).OpenDatabase(Application _
.DefaultFilePath & "\NWINDEX.MDB")
Set rs1 = db.OpenRecordset("SELECT * FROM Customer" _
& " WHERE [REGION] = 'WA' ORDER BY [CUSTMR_ID];")
Set companySheet = Worksheets.Add
companySheet.Name = "COMPANY"
Set idSheet = Worksheets.Add
idSheet.Name = "CUSTMR_ID"
Set rs2 = rs1.Clone()
rs2.MoveFirst
Do Until rs1.EOF
companySheet.Cells(rs1.AbsolutePosition + 1, 1).Value = _
rs1.Fields("COMPANY").Value
rs1.MoveNext
Loop
Do Until rs2.EOF
idSheet.Cells(rs2.AbsolutePosition + 1, 1).Value = _
rs2.Fields("CUSTMR_ID").Value
rs2.MoveNext
Loop
rs1.Close
rs2.Close
db.Close