Iterating through a list box

  • Thread starter Thread starter D Collins
  • Start date Start date
D

D Collins

Hello,

I have 2 list boxes, one from which you choose something,
then I send it over to another list box to indicate that
it was chosen (just like a wizard). Here's my problem,
when I iterate through the list box to determine which one
(s) were selected, it takes forever. The source of the
list box is a table of approx. 3,000 choices from a
linked SQL table.

I do have other list boxes from which I choose items that
are also linked to a SQL table source, but they do have
less items.

Question: Is there a better way to accomplish what I
need (having a list box of 3,000 choices from which I
select several to move over to another list box) run
smoother, quicker?

Thanks, D.
 
How are you looping? If you're not using the ItemsSelected property then
you should be.
 
Here's what I have for code: How would I rewrite it with
what you suggest?

Thanks, D.

'Cycle through the listbox to find the selected item
For iI = 0 To oFromList.ListCount - 1
'Test whether the item is selected
If oFromList.Selected(iI) = True Then
'Copy the item to the target list
oToList.RowSource = oToList.RowSource &
oFromList.ItemData(iI) & ";"
Else
'Set the value for the source list
sList = sList & oFromList.ItemData(iI) & ";"
End If
Next
 
I would definitely try to avoid using value lists as the source for list
boxes given the amount of your data. Is it possible to add a 'Chosen' (or
whatever) boolean field to the underlying table?

One other point... list boxes containing 3000 items are not going to be at
all user friendly. Do you have - or is it possible to add - some method of
being able to filter the list?
 
Back
Top