Programmatically selecting an item in a Listbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In Access2002, I need to be able to programmatically select item(s) in a
Listbox control. I'll come in with a value, let's say "Right Leg", from a
table. I need to spin through all the rows in the Listbox (they won't be
selected at that point), and if the bound column has a value equal to my
text, I want to set that row = selected. How can I do that please?

Thanks a million!
 
Dim lngLoop As Long

For lngLoop = 0 To (Me.MyListbox.ListCount - 1)
If Me.MyListbox.Item(lngLoop) = "Right Leg" Then
Me.MyListbox.Selected(lngLoop) = True
Exit For
End If
Next lngLoop
 
Douglas said:
Dim lngLoop As Long

For lngLoop = 0 To (Me.MyListbox.ListCount - 1)
If Me.MyListbox.Item(lngLoop) = "Right Leg" Then
Me.MyListbox.Selected(lngLoop) = True
Exit For
End If
Next lngLoop


I think Doug meant that to be:

If Me.MyListbox.ItemData(lngLoop) = "Right Leg" Then
 
Back
Top