Search Listbox as you type
Search Listbox as you type
evbo [Programmer][OP]
22 May 02 11:35I 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
RE: Search Listbox as you type
jebry [Programmer] 22 May 02 11:44Hi!
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
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
RE: Search Listbox as you type
LittleSmudge [Programmer] 22 May 02 13:03How 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
& it will take up less space on your form.
'ope-that-'elps.
G LS