Selecting items in List Box

  • Thread starter Thread starter David.G
  • Start date Start date
D

David.G

Hello everyone!

I'm trying to add checkboxes that will select certain
items in a scrolling list box. Our entries fall into five
categories, and each of those categories is assigned a
checkbox. I would like to know how to write script so
when the checkbox is checked, all of the associated
entries in the listbox are selected.

Thanks for any help provided
David.G
 
Hi David,
Firstly, one of the columns in your listbox would have to contain the
category the item is associated with. You can easily have the query that
feeds the listbox provide this. You can make that column hidden as well.

Also, to make it easy, name the checkbox after the category.

So now in the check box's click event you could have
something like this:
Dim i As Integer
'not sure if you want to clear the selections first
For i = 0 To List0.ListCount - 1
Me.List0.Selected(i) = False
Next

If Me.unbreakable Then
For i = 0 To Me.List0.ListCount - 1
If Me.List0.Column(0, i) = Me.unbreakable.Name Then
Me.List0.Selected(i) = True
End If
Next i
End If

unbreakable is the name of my checkbox, List0 is my listbox.
Column 0 (the first column) contains the data I'm comparing against.

But, unless you're absolutely sure you're never going to add another category, you'd be
better off using a combo box to display the categories and having the user select one.
That way you don't have to add a checkbox every time you add a category.
 
Back
Top