cascading combo box (1 Viewer)

Eljefegeneo

Still trying to learn
Local time
Today, 01:40
Joined
Jan 10, 2011
Messages
904
I want to use a variation of the popular "search as you type combo box" using the following VBA. What I cannot figure out to do is populate the combo box selection criteria, as in the case below, if I want to have a cbo1, a first combo box, populate the field in the second combo box, cboFilter. For example, I have five fields that I want to use for search criteria. Surname, Organization, City, State and Zip. I typed a list in cbo1 that included all of the five above, but I can't figure out how to select the rowsource for the second box, cboFilter, so if I select Surname in cbo1, then I can start typing in cboFilter to search for a surname. Any suggestions?

Below uses the fieldPrivate Sub cboFilter_Change()

' If the combo box is cleared, clear the form filter.
If Nz(Me.cboFilter.Text) = "" Then
Me.Form.Filter = ""
Me.FilterOn = False

' If a combo box item is selected, filter for an exact match.
' Use the ListIndex property to check if the value is an item in the list.
ElseIf Me.cboFilter.ListIndex <> -1 Then
Me.Form.Filter = "[fieldName] = '" & _
Replace(Me.cboFilter.Text, "'", "''") & "'"
Me.FilterOn = True

' If a partial value is typed, filter for a partial fieldName match.
Else
Me.Form.Filter = "[fieldname] Like '*" & _
Replace(Me.cboFilter.Text, "'", "''") & "*'"
Me.FilterOn = True

End If

' Move the cursor to the end of the combo box.
Me.cboFilter.SetFocus
Me.cboFilter.SelStart = Len(Me.cboFilter.Text)

End Sub
 

Eljefegeneo

Still trying to learn
Local time
Today, 01:40
Joined
Jan 10, 2011
Messages
904
Well, it wasn't exactly what I was looking for, but it works fine. I will probably use it instead of my former idea. My only follow-up question is that I seemed to be limited to 9 "or" statements in the query. While this isn't a problem, is this true? Or is there a way around it.
Thanks again. You have saved me a great deal of time and effort.
 

John Big Booty

AWF VIP
Local time
Today, 18:40
Joined
Aug 29, 2005
Messages
8,263
Sorry I'm not sure as I've never pushed it to it's limits on that front :eek:
 

Users who are viewing this thread

Top Bottom