Filter ComboBox Options (1 Viewer)

LadyDi

Registered User.
Local time
Today, 03:30
Joined
Mar 29, 2007
Messages
894
I have a ComboBox on my form that has a lot of options (its for customer name). Is there a way that I can program the combobox so that once the user enters the first couple letters, the combobox will just show the customers starting with those letters?

For example, when the user enters BO, the options in the ComboBox will show things like Bob's Bank, Box Trust, Bobwhite Savings, etc.

Any assistance you can provide would be greatly appreciated.
 

James Deckert

Continuing to Learn
Local time
Today, 05:30
Joined
Oct 6, 2005
Messages
189
I have comboboxes that are alphabetized and I can start typing and it'll jump to the first record which matches. It doesn't eliminate to only those letters, like you're asking. But this is close. Is it close enough for you? This is the way it works without doing anything.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:30
Joined
Aug 30, 2003
Messages
36,130
I do the same thing as James (often also dropping the combo on focus). If you really want to filter:

http://allenbrowne.com/ser-32.html
 

LadyDi

Registered User.
Local time
Today, 03:30
Joined
Mar 29, 2007
Messages
894
Thank you for the information. I appreciate it.

I added the code from the Allen Browne website and modified it for my Customer table. However, when I try to run it, I get the "Function not defined" error. Below is the code that I've added, could you tell me what I'm doing wrong?
Code:
Dim sCustStub As String
Const conCustMin = 3
Public Function ReloadCust(sCust As String)
    Dim sNewStub As String    ' First chars of Suburb.Text
     sNewStub = Nz(Left(sSuburb, conCustMin), "")
    ' If first n chars are the same as previously, do nothing.
    If sNewStub <> sCustStub Then
        If Len(sNewStub) < conCustMin Then
            'Remove the RowSource
            Me.Customer.RowSource = "SELECT Customer FROM CustomerNameTbl WHERE (False);"
            sCustStub = ""
        Else
            'New RowSource
            Me.Customer.RowSource = "SELECT Customer FROM CustomerNameTbl WHERE (Customer Like """ & _
                sNewStub & "*"") ORDER BY Customer;"
            sCustStub = sNewStub
        End If
    End If
End Function
Code:
Private Sub Form_Current()
Call ReloadCust(Nz(Me.Customer, ""))
End Sub
Code:
Private Sub Customer_Change()
Dim cbo As ComboBox         ' Suburb combo.
    Dim sText As String         ' Text property of combo.
     Set cbo = Me.Customer
    sText = cbo.Text
    Call ReloadCust(sText)
    Set cbo = Nothing
End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:30
Joined
Aug 30, 2003
Messages
36,130
On what line?
 

Users who are viewing this thread

Top Bottom