Connecting combo boxes

  • Thread starter Thread starter ladybug via AccessMonster.com
  • Start date Start date
L

ladybug via AccessMonster.com

I want two combo boxes where depending on what you select from the first one
will bring up a certain list on the second combo box.

Example: First combo box lists the states. When you select your state, only
the cities that are in that state will appear in the second combo box.

How do I set up the tables and these two fields in a form?
 
Assume cb1 has the states and cb2 lists the cities, you need the following
code pattern in the AfterUpdate event of cb1

If IsNull(cb1) then
' clear the city list
cb2.RowSource = ""
Else
' set the rowsource to filter for the selected state
cb2.RowSource = "Select [CityTable].[City] " _
& "From [CityTable] "
& "Where [CityTable].State = '" & cb1 & "'"
End If

Note the single quotes embedded into the Where claues - they are important
otherwise the content of cb1 will be misinterpreted. You may also widh to
run that afterupdate code in the OnCurrent event of the form if cb1 is a
bound control. That will always update the ciry list to the current record's
state value

HTH
 
Back
Top