[RESOLVED] Search within ComboBox
Hi all,
I would like to create a combo box in my VBA where the user can either expand the list and select it, OR allow the user to input the relevant letters and it will search for the closest one.
For example, in the combo box i have
1) Line
2) Lime
3) Lice
4) Like
5) Limousine
When the user first type in L or Li, all 4 will appear, and if the user type in the 3rd character, say Lim, then Lime and Limousin will be on the list.
Or when the user type in i or e, all 5 will still be displayed because they all have this character.
Can anyone help me out or any advise? I hope I am clear enough...:bigyello:
Thanks!
OB
Re: Search within ComboBox
hi oceanboy, try this:
i supposed your combo box is in a form..
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Private Sub ComboBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Call SendMessage(Application.hwnd, CB_FINDSTRING, 1, ByVal CStr(ComboBox1.ListIndex))
End Sub
Private Sub UserForm_Initialize()
ComboBox1.AddItem "Lime"
ComboBox1.AddItem "Limousine"
ComboBox1.AddItem "Line"
ComboBox1.AddItem "Like"
ComboBox1.AddItem "Live"
ComboBox1.AddItem "Life"
ComboBox1.AddItem "Lice"
End Sub
Re: Search within ComboBox
at the end...i just re-create a new rowsource for the combobox everytime a character is keyed in. thanks for your reply though.