Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

ADO Recordset using Excel as a database. Can't free the memory once opperation is over?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Denis B?land - 30 Dec 2004 12:00 GMT
Hello.

Thanks for reading, hopefully one of you will have a suggestion.

I have 3 sheets of data in an Excel workbook. Those data where prevouisly
imported from an SQL database.

I need to perform many filtering opperation on those datas to fill different
tables with the numbers of rows left after the
filter is applied.

After creating a connection object and a recordset, i pass the recordset to
a funtion. Here is a portion of this funtion.

           With rstX
               If .State = adStateClosed Then
                   .Source = strSql   -----------------> exeample "SELECT *
FROM [Data1$] Where RefCat IN (2,5,10,15)"
                   .Open , , adOpenStatic, adLockReadOnly
               End If
           End With
           For i = 1 To 3
               rstX.Filter = "Date>='" & CLng(Fonctions.Cells((5 + i),
3).Value) & "' And Date<='" & CLng(Fonctions.Cells((5 + i), 4).Value) & "'"
               tabRange.Cells(j, (i * 2)).Value = rstX.RecordCount
           Next i
           rstX.Close

The funtion retuns an integer indicating if the opperation was successfull.

After all the filter are over the calling sub puts the recordset object and
the ado connection to nothing.

I call this function over 40 in the same event ( click of a button )

My problem comes with the memory usage. For some reason excel seems to store
the result set of all the Select .
When i'm done excel use 110 megs of memory and if i start the opperation
again it will build up more memory until the available memory is full.

It wont free that memory until i close Excel itself, closing the workbook
does not do it.

Thank you !

Signature

Denis B?land

denisbeland@hotmail.com

Andi Mayer - 30 Dec 2004 14:28 GMT
On Thu, 30 Dec 2004 07:00:11 -0500, "Denis Béland"
<denisbeland@hotmail.com> wrote:

>Hello.
>
>Thanks for reading, hopefully one of you will have a suggestion.
>
>I have 3 sheets of data in an Excel workbook. Those data where prevouisly
>imported from an SQL database.

I would use a total different aproach:

import direct from the SQL database

or if you have to use the Excel.

Dim ary() As Variant
Dim objExcel As Object
Dim aRange As Object
Dim MyRows as long, MyCols as Long

Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Visible = False 'True
objExcel.workbooks.Open "C:\MyExcel.xls")

With objExcel.Application.activeWorkBook
   Set aRange = .activesheet.usedRange
   ary = aRange
   Set aRange = Nothing
   .Close False
End With
objExcel.Quit
Set objExcel = Nothing

myRows= UBound(ary)
myCols = UBound(ary, 2)

Now I can use this array to filter the data and write the tables

---
If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.