J
Jey
I'm exporting an access recordset to excel. My questions are:
1) Is there a faster way? A large recordset can take over 1/2 an hour!
2) Some of my recordsets will have over 100,000 records. What's the best
(most efficient) way to set up a loop to separate it into multiple worksheets
with no more than 65,000 records per worksheet?
My code so far is:
Dim strSQL As String
Dim DB As Database
Set DB = CurrentDb()
Dim RS As Recordset
Dim objXL As Excel.Application
Dim objWS As Excel.worksheet
Dim fld As Field
Dim intCol As Integer
Dim intRow As Integer
strSQL = "SELECT ...blah blah blah..."
Set RS = DB.OpenRecordset(strSQL) 'create recordset
'create and name worksheet
Set objWS = objXL.Worksheets.Add 'opens a new sheet in the workbook
objWS.Name = "BLAH" 'names the new sheet
'copy to worksheet
'first the field names
For intCol = 0 To RS.Fields.Count - 1
Set fld = RS.Fields(intCol)
objWS.Cells(1, intCol + 1) = fld.Name
Next intCol
'now the actual data
intRow = 2
Do Until RS.EOF
For intCol = 0 To RS.Fields.Count - 1
objWS.Cells(intRow, intCol + 1) = RS.Fields(intCol).Value
Next intCol
RS.MoveNext
intRow = intRow + 1
Loop
Thanks in advance for any advice!
1) Is there a faster way? A large recordset can take over 1/2 an hour!
2) Some of my recordsets will have over 100,000 records. What's the best
(most efficient) way to set up a loop to separate it into multiple worksheets
with no more than 65,000 records per worksheet?
My code so far is:
Dim strSQL As String
Dim DB As Database
Set DB = CurrentDb()
Dim RS As Recordset
Dim objXL As Excel.Application
Dim objWS As Excel.worksheet
Dim fld As Field
Dim intCol As Integer
Dim intRow As Integer
strSQL = "SELECT ...blah blah blah..."
Set RS = DB.OpenRecordset(strSQL) 'create recordset
'create and name worksheet
Set objWS = objXL.Worksheets.Add 'opens a new sheet in the workbook
objWS.Name = "BLAH" 'names the new sheet
'copy to worksheet
'first the field names
For intCol = 0 To RS.Fields.Count - 1
Set fld = RS.Fields(intCol)
objWS.Cells(1, intCol + 1) = fld.Name
Next intCol
'now the actual data
intRow = 2
Do Until RS.EOF
For intCol = 0 To RS.Fields.Count - 1
objWS.Cells(intRow, intCol + 1) = RS.Fields(intCol).Value
Next intCol
RS.MoveNext
intRow = intRow + 1
Loop
Thanks in advance for any advice!