Create a Text Box/List Box combination.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mricketson
    New Member
    • Dec 2009
    • 2

    Create a Text Box/List Box combination.

    Create a Text Box/List Box combination like the one in Windows Help. As you type in the Text portion of the Text Box, the List Box will scroll to whatever has been typed so far.
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    The standard Access Combobox control works this way with the AutoExpand property set to Yes, which is the default setting.

    Welcome to Bytes
    !

    Linq ;0)>

    Moderator

    Comment

    • mricketson
      New Member
      • Dec 2009
      • 2

      #3
      That would work if I could get the combo box to expand as you typed.

      Comment

      • topher23
        Recognized Expert New Member
        • Oct 2008
        • 234

        #4
        The combo box is very useful, but if you'd really like to do something like what you mentioned, you could try this. This will set up a list box which displays a list of items filtered by what you type into a text box.

        Example: if you type "dog," the list box will display all items containing the word "dog," including "Doggy Bag," "Iams Dog Food" and "Bad Dog." A combo box would only show the items that start with "dog," i.e. "Doggy Bag."

        Assume your search involves a field called txtSearchField in a table called tblMain.

        On your form, create a text box called txtFinder, and a list box called lstPicker.
        Set lstPicker's rowsource to
        Code:
        SELECT txtSearchField FROM tblMain 
        WHERE txtSearchField Like ("*" & [txtFinder] & "*") 
        OR txtSearchField Like ([txtFinder] & "*") 
        OR txtSearchField Like ("*" & [txtFinder])
        Then, put this code in txtFinder's On Key Up event.

        Code:
            lstPicker.SetFocus
            lstPicker.Requery
            With txtFinder
                .SetFocus
                .SelStart = Len(.Text)
            End With
        I hope this works for you!

        Comment

        • OldBirdman
          Contributor
          • Mar 2007
          • 675

          #5
          Assuming the name of the ComboBox is cboTestBox, then the code
          Code:
          Private Sub cboTestBox_GotFocus()
          cboTestBox.Dropdown
          End Sub
          should do what you want if AutoExpand = True.

          I have seen other threads that discourage use of GotFocus/LostFocus, and maybe some other event can be used. I didn't try, but I did test the above code.

          Comment

          Working...