Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Listbox as you type

Status
Not open for further replies.

evbo

Programmer
May 22, 2002
2
0
0
US
I have a listbox of students names and want to be able to type a name in a textbox and have the listbox choose the proper name with each letter that I type. So when I type an L it takes me to the first L lastname, then when I type an A it will take me to the first person with LA as their last name. If anyone could help me figure this out I would appreciate it. Thanks
 
Hi!

Use this code in the textbox change event:

Dim lngBoxLength As Long
Dim intRow As Integer
Dim strTextBox As String

strTextBox = YourTextBox.Text
lngBoxLength = Len(YourTextBox.Text)

For intRow = 0 To YourListBox.ListCount - 1
If Left(YourListBox.Column(0, intRow), lngBoxLength) = strTextBox Then
YourListBox.Selected(intRow) = True
Exit For
Next intRow

hth
Jeff Bridgham
bridgham@purdue.edu
 
How about using a COMBO box instead of a list box, because then you can set the "Auto Expand" property to Yes and it will do EXACTLY what you're asking for.

& it will take up less space on your form.


'ope-that-'elps.

G LS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top