Help!

Best way to execute an SQL Query on an Excel Worksheet

 
  

Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Query DAO RSS
Next:  Drop Down box resizing on open  
Author Message
Jenny C.
External


Since: Nov 23, 2006
Posts: 1



PostPosted: Thu Nov 23, 2006 3:04 pm    Post subject: Best way to execute an SQL Query on an Excel Worksheet
Archived from groups: microsoft>public>excel>querydao (more info?)

Hi,

Several times in the past I have queried Excel Spreasheet from .NET code
using an OleDbConnection and a connection string of the type :
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mypath\myfile.xls Extended
Properties="Excel 8.0;HDR=Yes;";". And this worked just fine.

Now I'm trying to do the same thing, but from the vba code of the Excel file.
I have several queries ( all of them are of the type "Select SUM(field)",
and they returne only one value ) that I need to execute on the data of the
current Excel file.

I have first used the same approach with the following :

Dim conCalculsExcel As String
conCalculsExcel = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
pathExcel & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"

Dim conExcel As ADODB.Connection
Set conExcel = New ADODB.Connection
conExcel.Open conCalculsExcel

Dim rset As ADODB.Recordset
Set rset = New ADODB.Recordset

Dim myQuery As String
myQuery = "SELECT SUM(TOTAL) FROM ...."

rset.Open myQuery, conExcel, adOpenStatic, adLockOptimistic

.....

rset.Close
Set rset = Nothing


All this works for a couple of times...
But I need to execute this about 700 times in one process,
and each time I open a Recorset it take about 4 Megs of RAM...
So I quickly run out of memory...

How do I release the memory taken by a Recorset after I used it ?

Or is there a better way to do this when you want to query directly in the
current Worksheet ?

Thanks a million for your help!!!


Jenny
Back to top
redan



Joined: Aug 27, 2007
Posts: 2



PostPosted: Mon Aug 27, 2007 7:31 am    Post subject:

Hello,

I have the same problem. Did u get an answer, if so could you please share it.

thanks in advance.
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Query DAO All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum