big_grasshopper
asked on
Autocomplete Combo Box question.
I have a combo box (cbState) which has all 50 states. My problem is when I begin typing in the state, it's isn't autocompleted like what it is in access. I would like to know how to accomplish this.
I'm assuming the combo box is sorted. The this will do the trick
Private Sub cboMyCombo_Change()
Dim i As Long
For i = 0 To cboMyCombo.ListCount - 1
If cboMyCombo.List(i) = cboMyCombo.text Then
cboMyCombo.ListIndex = i
cboMyCombo.SelStart = 0
cboMyCombo.SelLength = Len(cboMyCombo.text)
Exit For
End If
Next n
End Sub
Private Sub cboMyCombo_Change()
Dim i As Long
For i = 0 To cboMyCombo.ListCount - 1
If cboMyCombo.List(i) = cboMyCombo.text Then
cboMyCombo.ListIndex = i
cboMyCombo.SelStart = 0
cboMyCombo.SelLength = Len(cboMyCombo.text)
Exit For
End If
Next n
End Sub
Should say:
Next i
Next i
You could always just change the style to DropDownList, then it will match on the first letter as the user types. Or alternatively you could switch to using a DBCombo which supports a MatchEntry property which should provide what you want.
Hope this helps.
Hope this helps.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I want to thank all of you, but wow. The code from brianb99999 works GREAT.
http://www.freevbcode.com/ShowCode.Asp?ID=2266
S