I would really use a combo box for this. The behaviour you are looking for
is native to it. (autoexpand)
However if you must use a combination of text box and list box...
(incidentally this is what a combo is and where the name comes from)
Private Sub Text2_Change()
Dim lb As ListBox
Dim i As Integer
Dim textlen As Integer
Dim txt As String
txt = Me.Text2.Text 'name of your text box
textlen = Len(txt) 'length of the text in the tb
Set lb = Me.List0 '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
This is iterative code so your list box should probably be sorted and have
as few items as possible.
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.