[Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

Drop down list or Combo box

I'm trying to create a box on a form that will auto search as text is typed
i.e. I have filled a combo box with a list of names. I have changed the properties of the box to drop down list. If I type a "H" in the box the drop down list moves to the first accurance of "H". This is good. However when I type a  "a "the drop down moves to the first accurrance of a. What I want it to do is move to the first accurrance of Ha.

Can someone help
2 Solutions
Hopefull this will help and get you started in the right direction

Add a module to your project
Add the following exactly as it is:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String) As Long
Private Const CB_FINDSTRING As Long = &H14C
Private Const CB_ERR = (-1)

Sub AutoCombo(cboCombo As Object)
Dim strPartial As String
Dim lngRETP As Long
Dim strTotal As String
Dim lngLen As Long

strPartial = cboCombo.Text
lngRETP = SendMessage(cboCombo.hwnd, CB_FINDSTRING, -1, ByVal strPartial)
If lngRETP <> CB_ERR Then
        strTotal = cboCombo.List(lngRETP)
        lngLen = Len(strTotal) - Len(strPartial)
        If Not lngLen = 0 Then
            cboCombo.SelText = Right$(strTotal, lngLen)
            cboCombo.SelStart = Len(strPartial)
            cboCombo.SelLength = lngLen
        End If
    End If
End Sub

In any form
In any combo box's Change event add something like the following (comboname will change depending on the name of your combo box):
Call AutoCombo(ComboName)

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now