Set rst = CurrentDb.OpenRecordset(sSQL)
'Redim array and store headings
With rst
.MoveLast
lngFieldCount = .Fields.Count - 1
lngRecordCount = .RecordCount
ReDim vTable(0 To lngRecordCount, 0 To lngFieldCount)
.MoveFirst
Do Until .EOF
For lngFieldCounter = 0 To lngFieldCount
If lngCurrentRecord = 0 Then
vTable(lngCurrentRecord, lngFieldCounter) = .Fields(lngFieldCounter).Name
Else
vTable(lngCurrentRecord, lngFieldCounter) = .Fields(lngFieldCounter).Value
End If
Next lngFieldCounter
lngCurrentRecord = lngCurrentRecord + 1
If lngCurrentRecord > 1 Then
.MoveNext
End If
Loop
End With
I use this snippet to pack a rst into an array and then export it to Excel thru aUtomation.
With oWS
.Range(.Cells(1, 1), .Cells(lngRecordCount + 1, lngFieldCount + 1)).Value = vTable
.Columns.AutoFit
End With