Trying to do a loop here to cycle through a list box and get the value at each index in the list. For some reason it's not working though. Here's the code:
Private Sub Command9_Click()
Dim Test As Integer
Dim Choice As String
Dim Y As Integer
'get the total number of items in the list box here
Test = Me.lstQueryList.ListCount
' start the loop to cycle through and get the values
For Y = 0 To (Test - 1)
' select the first value in the list box
lstQueryList.Selected(Y) = True
' assign the value to a variable
Choice = lstQueryList.Value
' prompt the variable in a mesage box
MsgBox "it is " & Choice
' deselect the item
lstQueryList.Selected(Y) = False
' go to the next item
Next Y
End Sub
It's weird, because when I'm viewing the text box on the form, I can see it cycling through the list properly. Howver, my message box keeps popping up with the first value from the list and does not progress like I would expect.
Surely, there's an easy way to do this, and I'm just to tire to get it right now.
Any help (as always) is greatly apprectiated.
THANKS!!
Private Sub Command9_Click()
Dim Test As Integer
Dim Choice As String
Dim Y As Integer
'get the total number of items in the list box here
Test = Me.lstQueryList.ListCount
' start the loop to cycle through and get the values
For Y = 0 To (Test - 1)
' select the first value in the list box
lstQueryList.Selected(Y) = True
' assign the value to a variable
Choice = lstQueryList.Value
' prompt the variable in a mesage box
MsgBox "it is " & Choice
' deselect the item
lstQueryList.Selected(Y) = False
' go to the next item
Next Y
End Sub
It's weird, because when I'm viewing the text box on the form, I can see it cycling through the list properly. Howver, my message box keeps popping up with the first value from the list and does not progress like I would expect.
Surely, there's an easy way to do this, and I'm just to tire to get it right now.
Any help (as always) is greatly apprectiated.
THANKS!!