Programmatically selecting an item in a Listbox

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!
 
D

Douglas J. Steele

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
 
M

Marshall Barton

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top