>> Find value in 2nd Column of listbox

J

Jonathan

Hi, using Access 2003 I would like to find the index of the row that contains
a specific value in the 2nd column of a combobox and then display this
specific item.

Any ideas or suggestions appreciated :)

Many thanks,
Jonathan
 
D

Douglas J. Steele

Dim lngLoop As Long

For lngLoop = 0 To Me!MyListbox.ListCount
If Me!MyListBox.Column(1, lngLoop) = "Some Value" Then
MsgBox "I found it in row " & lngLoop
Exit For
End If
Next lngLoop

The Column collection starts numbering at 0, so Column(1, lngLoop)
represents the value in the second column of the row specified.

Note, too, that if you're got the column headings turned on in your list
box, you need to start at 1, not 0. I never use column headings, so I don't
bother, but you could use

For lngLoop = - (Me!MyListBox.ColumnHeads) To Me!MyListbox.ListCount
 
J

Jonathan

supurb thank you

Jonthan

Douglas J. Steele said:
Dim lngLoop As Long

For lngLoop = 0 To Me!MyListbox.ListCount
If Me!MyListBox.Column(1, lngLoop) = "Some Value" Then
MsgBox "I found it in row " & lngLoop
Exit For
End If
Next lngLoop

The Column collection starts numbering at 0, so Column(1, lngLoop)
represents the value in the second column of the row specified.

Note, too, that if you're got the column headings turned on in your list
box, you need to start at 1, not 0. I never use column headings, so I don't
bother, but you could use

For lngLoop = - (Me!MyListBox.ColumnHeads) To Me!MyListbox.ListCount
 

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