Link to home
Start Free TrialLog in
Avatar of big_grasshopper
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.
Avatar of Shauli
Shauli

Avatar of JR2003
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
Should say:

    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.
ASKER CERTIFIED SOLUTION
Avatar of brianb99999
brianb99999

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of big_grasshopper

ASKER

I want to thank all of you, but wow. The code from brianb99999 works GREAT.