>> Find value in 2nd Column of listbox

  • Thread starter Thread starter Jonathan
  • Start date Start date
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
 
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
 
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
 
Back
Top