Drop down list or Combo box

Posted on 2006-05-10
Last Modified: 2010-08-05
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
Question by:whiwex
    LVL 24

    Accepted Solution

    LVL 1

    Assisted Solution

    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)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 Specialist

    HTML5 development skills are critical to all developers. HTML5 is the foundation to almost any development process. That's why business, design studios, development shops and other organizations need HTML5 developers. Get your foot in the door as a HTML5 specialist.

    Suggested Solutions

    Title # Comments Views Activity
    fizzArray2 challenge 1 44
    How to split this in C++ 4 49
    object oriented javascript web form 8 48
    groovy example issue 10 32
    This article is filled with multiple code samples and explanations for mathematical calculations. They are as follows: 1. General tips 2. Quadratic formula 3. Object collision 4. Projectile path General Tips       Here are some of my tips f…
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now