-
i want to create a combo box that will dynamically scroll according to what a user enters into a TEXT BOX. If you go into the VB help section and click on the index tab and start typing the combo box or list box dynamically scrolls down according to the alphebetic letters the user is typing into the above text box.
-
I can help you if you'll settle for using a listbox instead of a combo (I'm sure there's a way to do it with a combo, but I'm not sure how).
Anyway, I tested the following and it works:
Put a textbox and listbox on a form, set the listbox's Sorted property to True.
In a module, put the following code:
Code:
Public Declare Function sendMessageByString Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As String) As Long
Public Const LB_SELECTSTRING = &H18C
In your form, put the following code in the indicated events:
Code:
Private Sub Form_Load()
With Combo1
.AddItem "Hamburger"
.AddItem "French Fries"
.AddItem "Coca Cola"
.AddItem "Cheeseburger"
.AddItem "Fried Chicken"
.AddItem "Apple Pie"
End With
End Sub
Private Sub Text1_Change()
Dim lngEntryNum As Long
Dim strTextToFind As String
strTextToFind = Text1.Text
lngEntryNum = sendMessageByString(Combo1.hwnd, LB_SELECTSTRING, _
0, strTextToFind)
End Sub
I hope this helps.