 |
| Excel VBA Discuss using VBA for Excel programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 16th, 2004, 11:36 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ado excel/access
Hi there
I'm pulling data from a 3GB Access database using Excel VBA and ADO. I'm retrieving 250 fields for 100,000 records using a single active connection, and I'm further using the .Open Method (of the Recordset object), the .Execute Method (of the Connection object) and the CopyFromRecordset Method. I do this iteratively, i.e.
For i = 1 to 107288
rsData.Open strSQL, cnData, adOpenForwardOnly, adLockReadOnly, adCmdText
Worksheets(i).Cells(1, 1).CopyFromRecordset rsData
Next i
Doing things this way takes about 38 hours to pull all the data into an Excel workbook!
Is there a more efficient way to pull data from Access into Excel?
Best regards
Loane
|
|

August 16th, 2004, 03:05 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Never heard of anyone using 107288 sheets in a workbook. If you can do with a single sheet, try this:
rsData.Open strSQL, cnData, adOpenForwardOnly, adLockReadOnly, adCmdText
If Not rsData.EOF Then
Sheets("Sheet1").Cells(1, 1).CopyFromRecordset rsData
End If
rsData.Close
Set rsData = Nothing
|
|

August 17th, 2004, 01:21 AM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
Just for your information,Excel(2000) only allow 65636 rows in one sheet so to use the method suggested you will ned to add som logic that will change to another sheet when you reach the limit.
Cheers
Karsten
|
|

August 17th, 2004, 08:06 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi there, thanks for the suggestions.
I've added timers to my procedure and find approximately the following: 50% of the run time is spent running through my code (especially If ... End If, For ... Next and Do While ... Loop statements); 25% for the [Recordset].Open operation; and 25% for the [Range].CopyFromRecordSet operation.
Even taking out the code altogether, leaving only the ADO references, still involves a heck of a lot of time.
P.S. To overcome the 2^16 problem I'm using ...
For i = 1 to 107288
If i <= 2^16 Then
shtName = "Sheet1"
Else:
shtName="Sheet2"
End If
[other stuff here]
Next i
Thanks again
|
|

August 17th, 2004, 09:02 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It's just that in seems to me you're doing a lot of stuff within your loop that takes time.
Would it be possible to split your query in 2, e.g. run a Q on half of your data being sure it can fit into one sheet and doing it once more for the rest of the data for a second sheet ?
|
|

August 17th, 2004, 10:18 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Loane,
I gotta ask - what on earth are you trying to do here anyway? I'm thinking that if this is your problem, you're possibly trying to solve the wrong thing. What are you intending to do with all this data once you've got it?
Chris
There are two secrets to success in this world:
1. Never tell everything you know
|
|
 |