Initializing ListBox

alinagoo

New member
Local time
Today, 20:06
Joined
Jun 23, 2010
Messages
3
hello all
I hope you're happy

I've encountered a problem! Please help me if you can.
The problem is about ListBox Initialization! I'm using a query to select a column's values from a table and filling the ListBox with that values. It works great when records number are low but when records number reach to thousands the initialization of ListBox becomes so slow! do you have any offer for me to speed up the process of initialization? thanks so.

Code:
Private Sub EnableRelatedListBox(ListBoxTag As String)
Dim lngRow As Long
Dim ctl As Control
Dim check As CheckBox
Dim lst As ListBox
Dim SqlStr As String

Set check = Me.Controls(ListBoxTag)
Set lst = Me.Controls("List" & ListBoxTag)
If check.Value Then
SqlStr = "SELECT ResultedTableForMmtReport." & ListBoxTag & " FROM ResultedTableForMmtReport GROUP BY ResultedTableForMmtReport." & ListBoxTag & ";"

  For Each ctl In Me.Controls                 'Query every Control on the Form
     If ctl.ControlType = acListBox Then      'Is it a Check Box?
        ctl.Visible = False
     End If
  Next
 lst.Visible = True
 lst.Enabled = True
 lst.RowSource = SqlStr
 TempVars(ActiveControl.Tag & "st").Value = " (1=1) "
 Me.Refresh
 For lngRow = 0 To lst.ListCount - 1
    lst.Selected(lngRow) = True
 Next
Else
 For lngRow = 0 To lst.ListCount - 1
     lst.Selected(lngRow) = False
 Next
    lst.Visible = False
    lst.Enabled = False
    lst.RowSource = ""
    TempVars.Remove (lst.Tag & "st")
    Me.Refresh
End If
Set ctl = Nothing
Set lst = Nothing
Set check = Nothing
End Sub
 
Try

SqlStr = "SELECT DISTINCT ResultedTableForMmtReport." & ListBoxTag & " FROM ResultedTableForMmtReport"

Also make sure the field you are using in the ResultedTableForMmtReport table is indexed.
 
Hi
sure
it is useful.
thanks
 

Users who are viewing this thread

Back
Top Bottom