G
Guest
I have a list box and a textbox that I will use to search through my records.
I have created a slip of code that works, but only in the first column. How
can I make it search all the columns?
Here's the code:
Private Sub soktext_Change()
Dim lb As ListBox
Dim i As Integer
Dim textlen As Integer
Dim txt As String
txt = Me.soktext.Text 'name of your
text box
textlen = Len(txt) 'length of the
text in the textbox
Set lb = Me.Oppslist 'name of your
list box
For i = 1 To lb.ListCount 'for every item
in the list
If Left(lb.ItemData(i), textlen) = txt Then 'does it match?
lb.Selected(i) = True 'select the item
Exit For 'don't
bother with the rest
End If
Next
End Sub
I have created a slip of code that works, but only in the first column. How
can I make it search all the columns?
Here's the code:
Private Sub soktext_Change()
Dim lb As ListBox
Dim i As Integer
Dim textlen As Integer
Dim txt As String
txt = Me.soktext.Text 'name of your
text box
textlen = Len(txt) 'length of the
text in the textbox
Set lb = Me.Oppslist 'name of your
list box
For i = 1 To lb.ListCount 'for every item
in the list
If Left(lb.ItemData(i), textlen) = txt Then 'does it match?
lb.Selected(i) = True 'select the item
Exit For 'don't
bother with the rest
End If
Next
End Sub