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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search as You Type ~~ Narrow Down List 1

Status
Not open for further replies.

Roam2k2

Programmer
Aug 4, 2008
9
CA
Alright, so what i'm trying to do is have a box ( be it a combo box or list box ) and as you start typing, options will appear that correspond to what you type. For instance, if the list box has item's 'Apple', 'Banana', 'Cake', 'Anger'......As you type, 'A'...Apple and Anger should appear and when u type further it simply narrows down the list. It's like in facebook, when ur searching for one ur buddies...how it narrows down the list...hope that's clear enough... Any ideas how i'd go about this ? I've searched numerous sites and couldn't piece together a solution (most of the solutions were for vb6)...Thanks for all your help. I'll be using it in word '03.

- Roam.
 
Never done it in word, but this works in Excel...

Private Sub TextBox1_Change()
ListBox1.ListIndex = -1
For x = 0 To ListBox1.ListCount - 1
ListBox1.ListIndex = x
z = ListBox1.Text
If LCase(Left(ListBox1.Text,Len(TextBox1.Text))) = LCase(TextBox1.Text) Then
Exit Sub
End If
Next x
End Sub


Private Sub TextBox1_KeyPress(ByVal KeyAscii AS MSForms.ReturnInteger)
If KeyAscii = 13 Then 'User pressed Enter
KeyAscii = 0
' When triggered do something here
Exit Sub
End If
End Sub

Hope this helps

John
 
Well,

Just got back from a short test in word, and it appears the list and textbox works, but word doesn't treat the enter key as a keypressed event.

Interesting... now i'm curious, never played in Word VBA b4...

John
 
This works, though - not in keypressed

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then 'User pressed Enter
Stop
' When triggered do something here
Exit Sub
End If
End Sub

John
 
Anytime,

But I really should look at code b4 I post!

The two lines...

ListBox1.ListIndex = -1
z = ListBox1.Text

...Aren't needed and are really refuse lines, left over while I was playing...

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top