LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Correct approach for clearing memory with repeated Database queries

I'm using a VBA macro to repeatedly pull data from a MySQL database
using an ODBC connector. This is the main subroutine with the query
(note I've removed various things from the macro such as server,
username, password and the exact query which aren't important)

Sub DataImport()
Dim rRng As Excel.Range
Sheets("Imported Data").Select
Set rRng = Range("A1:F1000")

With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DATABASE= ;DRIVER={MySQL ODBC 3.51
Driver};OPTION=0;;PORT=0;SERVER= ;UID= ;PASSWORD= " _
, Destination:=rRng)
.CommandText = Array( _
"SELECT * FROM table WHERE " _
)
.Name = "Query from Database"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Set rRng = Nothing

End Sub


The data gets dumped in the worksheet Imported Data.

I have another macro with a loop to run this query with different data
each time. The loop runs through about 1000 cases and each time I do
my analysis in another worksheet. Before I do a new import, I call
Selection.ClearContents and Selection.Clear to remove the previous
data.

The problem is that when I click on the imported data worksheek, my
CPU usage goes to 100%. I noticed that in the Excel Name Box
the .Name field "Query from Database" shows up numerous times.

My questions a
1) Why does the query name show up in the Excel Name Box?
2) Is there something I'm not doing to clear the previous data or
release the memory?
3) Is there some way to reduce the CPU usage when I click on the
imported data worksheet?

Thanks.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Repeated web queries eventual return error 1004 PeterQ Excel Discussion (Misc queries) 0 March 1st 08 09:55 PM
clearing memory using VBA NathanG Excel Programming 1 October 30th 07 04:09 PM
Clearing Memory [email protected] Excel Programming 5 March 17th 06 01:21 AM
Clearing Memory [email protected] Excel Programming 1 March 16th 06 02:20 PM
Clearing Memory Jonny Excel Programming 2 December 7th 04 04:49 AM


All times are GMT +1. The time now is 06:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"