G
Guest
Can anyone suggest a faster way to copy a recordset to Excel via automation.
I'm currently using the following code, which copies each field across one at
a time. The recordset has 7 columns and, at times, 10000 records, so it's
taking forever to populate a worksheet. Here's the section of code that
handles the data transfer:
Set rstTasks = db.OpenRecordset(strTasksSQL, dbOpenSnapshot)
If rstTasks.EOF = False And rstTasks.BOF = False Then
rstTasks.MoveFirst
Do While rstTasks.EOF = False
For lngColumn = 0 To rstTasks.Fields.Count - 1
XLCell.Offset(0, lngColumn).Value = rstTasks.Fields(lngColumn).Value
Next lngColumn
rstTasks.MoveNext
Set XLCell = XLCell.Offset(1, 0)
Loop
End If
I was hoping there would be a command to copy the entire recordset in one
hit and just paste that into the worksheet. The workbook has x amount of
worksheets, so Access is creating them on the fly, formatting them and naming
them appropriately, so the OutputTo command is not an option here.
Thanks in advance
Dave
I'm currently using the following code, which copies each field across one at
a time. The recordset has 7 columns and, at times, 10000 records, so it's
taking forever to populate a worksheet. Here's the section of code that
handles the data transfer:
Set rstTasks = db.OpenRecordset(strTasksSQL, dbOpenSnapshot)
If rstTasks.EOF = False And rstTasks.BOF = False Then
rstTasks.MoveFirst
Do While rstTasks.EOF = False
For lngColumn = 0 To rstTasks.Fields.Count - 1
XLCell.Offset(0, lngColumn).Value = rstTasks.Fields(lngColumn).Value
Next lngColumn
rstTasks.MoveNext
Set XLCell = XLCell.Offset(1, 0)
Loop
End If
I was hoping there would be a command to copy the entire recordset in one
hit and just paste that into the worksheet. The workbook has x amount of
worksheets, so Access is creating them on the fly, formatting them and naming
them appropriately, so the OutputTo command is not an option here.
Thanks in advance
Dave