Find a value in a list box

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

Guest

I have a form containing a text box and a list box with multiple rows and
columns. When the user types a value in the text box, I want to find that
value in the list box and scroll to that row. Should be simple, but I don't
seem to be able to make it work.
 
Carol Grismore said:
I have a form containing a text box and a list box with multiple rows and
columns. When the user types a value in the text box, I want to find that
value in the list box and scroll to that row. Should be simple, but I don't
seem to be able to make it work.

Hi Carol, use the following code as an example...

the code searchs for a match with a value in the second column of the
listbox (list0)

**** code start ****


Private Sub Command4_Click()
Dim strData As String
Dim intLoop As Integer
Dim blnFound As Boolean

If Len(Text1) > 0 Then
strData = Text1
With List0
For intLoop = 0 To .ListCount - 1
If LCase(.Column(1, intLoop)) = LCase(strData) Then
.Selected(intLoop) = True
blnFound = True
Exit For
End If
DoEvents
Next intLoop

If Not blnFound Then
MsgBox "Can't find it"
End If
End With

End If
End Sub

*** Code End ****

Luck
Jonathan
 
Back
Top