How do you loop through a listbox?

Nirious

Registered User.
Local time
Today, 13:15
Joined
Jul 31, 2004
Messages
106
Actually the title says it all.

With for each or do while or something?
 
Not my strong point but here is how I loop through a list box...
Code:
    Dim frm As Form, ctl As Control
    Dim vItem As Variant
    
    Set frm = Forms!FormNameHere
    Set ctl = frm!ListBoxNameHere
    For Each vItem In ctl.ItemsSelected
        'Your action here
    Next vItem
 
  • Like
Reactions: Rx_
Nirious, I usually use the For, Next. Here's an example of how it can be used.

Dim intR as Integer

'lstActiveReports is my ListBox name

'Use this with Column Heads set to NO
For intR = 0 To lstActiveReports.ListCount
MsgBox lstActiveReports.column(0, intR)
'Use the .column to determine the (column, row) of the listbox

Next intR
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Use this with Column Heads set to YES
'With Columns Heads ON Row(0) refers to the Headings
For intR = 1 To lstActiveReports.ListCount - 1
MsgBox lstActiveReports.column(0, intR)
'Use the .column to determine the (column, row) of the listbox

Next intR

Hope this helps!
 
  • Like
Reactions: Rx_

Users who are viewing this thread

Back
Top Bottom