Looping through several Listboxes.

  • Thread starter Thread starter Denis
  • Start date Start date
D

Denis

Hello,

The code below works in deselecting multiple items
selected in a list box (lstEducation).

I have 8 list boxes where users will be able to select
one or more items in each of the list boxes. These items
will be used to generate a query later (I have THAT part
figured out - thanks to the assistance of Allen Browne).

What I am looking for here is a way to modify the code
below (or add new code) to loop through all 8 list boxes
and deselect all selected items using a Reset button
(cmdReset).

Thank you and this forum is GREAT!!

Denis




Private Sub cmdReset_Click()

Dim lc As Long
Dim ls As Long


Me.lstEducation.SetFocus
lc = Me.lstEducation.ListCount

For ls = 0 To lc - 1

If Me.lstEducation.Selected(ls) = True Then
Me.lstEducation.Selected(ls) = False
End If

Next ls


End Sub
 
Denis said:
Hello,

The code below works in deselecting multiple items
selected in a list box (lstEducation).

I have 8 list boxes where users will be able to select
one or more items in each of the list boxes. These items
will be used to generate a query later (I have THAT part
figured out - thanks to the assistance of Allen Browne).

What I am looking for here is a way to modify the code
below (or add new code) to loop through all 8 list boxes
and deselect all selected items using a Reset button
(cmdReset).

Thank you and this forum is GREAT!!

Shortcut: Just set the RowSource of each ListBox equal to itself. That results
in all selections being cleared.
 
Rick, thanks for your reply.
I guess what I am really looking for is this: when I
click on a button, I want the form to look for all
listboxes on the form, determine whether they have items
selected, and if so, deselect the items. I am trying to
find a way without having to list all the listboxes
individually in the code.

I guess the original post should have been posted in
the 'formscoding' forum. A copy of this is now
in 'formscoding'.

Thank you
Denis
 
BINGO!

Thank you, Dan. Back to work I go!!!
Cheers!
Denis
-----Original Message-----
Hi,
I think this is what you're looking for?

Dim ctl As Control
Dim i As Integer

For Each ctl In Me.Controls
If ctl.ControlType = acListBox Then
For i = 0 To ctl.ListCount - 1
If ctl.Selected(i) = True Then
ctl.Selected(i) = False
End If
Next i
End If
Next

--
HTH
Dan Artuso, Access MVP


"Denis" <[email protected]> wrote in
message news:[email protected]...
 
Hi,
I think this is what you're looking for?

Dim ctl As Control
Dim i As Integer

For Each ctl In Me.Controls
If ctl.ControlType = acListBox Then
For i = 0 To ctl.ListCount - 1
If ctl.Selected(i) = True Then
ctl.Selected(i) = False
End If
Next i
End If
Next
 
Back
Top