I've got a combobox that dynamically updates it's selection list based on previous selections. I've got this working pretty good. The problem is that every time I refresh the querytable, the memory usage goes up. Eventually, this would become a big problem if not addressed. After some searching I found this post on another site ( [URL unfurl="true"]http://www.ozgrid.com/forum/showthread.php?t=61780 [/url]) that says MS Query does in fact have memory issues and to use ADO instead.
My questions are:
1. Is the memory usage accusation against using the QueryTable correct?
2. If not, how do I address the memory issues I am seeing?
3. Either way, if I switched to using ADO and added the reference to my template file, would that cause any issues on the end-user's side when they use the file?
Here's the code that move's my combobox and refreshes the querytable/range/box selection if that helps any.
(btw, I'm also always up for constructive criticism of my code)
My questions are:
1. Is the memory usage accusation against using the QueryTable correct?
2. If not, how do I address the memory issues I am seeing?
3. Either way, if I switched to using ADO and added the reference to my template file, would that cause any issues on the end-user's side when they use the file?
Here's the code that move's my combobox and refreshes the querytable/range/box selection if that helps any.
(btw, I'm also always up for constructive criticism of my code)
Code:
Public Sub Move_cbCategory(aRange As Range)
Dim Obj As OLEObject
Dim c As Integer
Dim wsFiltered As Worksheet
Dim wsSelections As Worksheet
Dim sSQL As String
Dim SelAddr As String
Dim SelValue As String
Dim sText As String
Dim iLastRow As Integer
Application.ScreenUpdating = False
IgnoreEvents = True
Set Obj = ActiveSheet.OLEObjects("cbCategory")
Set wsFiltered = Worksheets("Filtered")
Set wsSelections = Worksheets("Selections")
c = aRange.Column
sText = aRange.Value
Obj.LinkedCell = aRange.Address
If c = 6 Then
sSQL = "select id, parentid, description from categories order by ID"
Else
SelAddr = aRange.Address
SelValue = wsSelections.Range(SelAddr).Offset(0, -1).Value
sSQL = "select id, parentid, description from categories where parentid = '" & SelValue & "' order by ID"
End If
With wsFiltered
With .QueryTables("qtFiltered")
.CommandText = sSQL
.Refresh False
iLastRow = GetLastRow("Filtered", 3)
If iLastRow = 1 Then GoTo CLEANUP 'only header row was returned
Obj.Object.Text = sText
Names.Add Name:="FilteredCats", RefersToR1C1:="=Filtered!R2C1:R" & iLastRow & "C3"
End With
With .Columns(3)
.AutoFit
Obj.Object.ListWidth = .Width + 30
aRange.ColumnWidth = .ColumnWidth + 6
End With
End With
With Obj
.Left = aRange.Left
.Top = aRange.Top
.Width = aRange.Width + 1
.Height = aRange.Height + 1
.ListFillRange = "FilteredCats"
.Visible = True
End With
IgnoreEvents = False
Application.ScreenUpdating = True
CLEANUP:
Set Obj = Nothing
Set wsFiltered = Nothing
Set wsSelections = Nothing