If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Filtering Records on a form using multiple combo boxes
Does anyone know how to use multiple combo boxes to filter records on a form?
Example: Combo Box 1- States Combo Box 2 - Cities (dependant on combo box 1) I have a table with contacts in the US and I want to be able to mix and match values in the combo box with matching records showing up on the form. For Example if I choose New York in the first combo box- I want the form to show all New York Contacts, then If I choose Albany in the 2nd combo box I want the records filtered out further to only show contacts in Albany, New York. Any thoughts? Thanks in advance. -- MSS |
#2
|
|||
|
|||
Filtering Records on a form using multiple combo boxes
(This is very rough aircode, and is only one possible approach.)
Dim mstrFormFilter as string Dim mstrCityFilter as string Dim mstrStateFilter as string sub cboCity_AfterUpdate mstrCityFilter = "= '" & cboCity & "'" Call SetFilter end sub sub cboState_AfterUpdate mstrStateFilter = "= '" & cboState & "'" Call SetFilter end sub sub SetFilter ' Allow for wildcards: don't assume a selection has been made in both combos. if len(mstrStateFilter) = 0 then mstrStateFilter = "Like *" if len(mstrCityFilter) = 0 then mstrCityFilter = "Like *" mstrFormFilter = "[State] " & mstrStateFilter & "' AND [City] " & mstrCityFilter & "'" Me.Filter = mstrFormFilter Me.FilterOn = True end sub -- George Nicholson Remove 'Junk' from return address. "Mark Senibaldi" wrote in message ... Does anyone know how to use multiple combo boxes to filter records on a form? Example: Combo Box 1- States Combo Box 2 - Cities (dependant on combo box 1) I have a table with contacts in the US and I want to be able to mix and match values in the combo box with matching records showing up on the form. For Example if I choose New York in the first combo box- I want the form to show all New York Contacts, then If I choose Albany in the 2nd combo box I want the records filtered out further to only show contacts in Albany, New York. Any thoughts? Thanks in advance. -- MSS |
Thread Tools | |
Display Modes | |
|
|