Excel VBA - Display Recordset in Sheet without looping

Viewed 128

I've got some code which retrieves data from an Access table into RecordSet. I want to display this data on my sheet but I'm struggling to do so. I've created a sheet called test whilst trying to figure this out and I've tried:

Test.Range("A1").CopyFromRecordset rs

But that doesn't do anything. I've been able to populate the sheet with

rs.MoveFirst
rowctr = 2
Do Until rs.EOF
    Test.Cells(rowctr, 1) = rs![Name]
    Test.Cells(rowctr, 2) = rs![Account Type]
    Test.Cells(rowctr, 3) = rs![Forecast Date]
    Test.Cells(rowctr, 4) = rs![Forecast Value]
    Test.Cells(rowctr, 5) = rs![Actual Date]
    Test.Cells(rowctr, 6) = rs![Actual Value]
    rowctr = rowctr + 1
    rs.MoveNext
Loop

But I'm assuming there's a better way than this? I've done this lots with normal arrays and have no issues populating a range with an entire array with a single command. I've not done too much work with records sets though.

0 Answers
Related