|
|
Cascading Combo Boxes Related Content: [edit] Cascading Combo Boxes (a.k.a. Synchronized Combo Boxes)
[edit] DefinitionCascading Combo Boxes are a series of 2 or more Combo Boxes in which each Combo Box is filtered according to the previous Combo Box. [edit] ExampleA simple example of where you could use Cascading Combo Boxes is a property address. Each address consists of a state, city, and zip-code. Three Combo Boxes will be used in this example. The first Combo Box, State, has a RowSource which lists all distinct states. When a user selects a state, the City Combo Box and the Zip Code Combo Box are both filtered to only the distinct cities and zip codes which reside within the selected state. (Note that this example does not filter the list of zip codes to reflect only zip codes associated with the selected City) This example is based on a normalized structure of three tables:
How-To: The City Combo Box would have as its RowSource property SQL for a query which places a WHERE condition on the Foreign Key, StateID, to equal the State Combo Box, like this: "SELECT * FROM tblCities WHERE StateID =" & cboState (cboState is the name of the state Combo Box). Its RowSourceType property would be set to Table/Query. The Zip Code Combo Box would also have as its RowSource property SQL for a query which places a WHERE condition on the Foreign Key, StateID, to equal the State Combo Box, like this: "Select * FROM tblZipCodes WHERE StateID =" & cboState. Again, its RowSourceType property would be set to Table/Query. In order to have the City and Zip Code Combo Boxes updated to reflect changes in the value contained in the State Combo Box, it's necessary to invoke the Requery method for the two Combo Boxes in a procedure called from the AfterUpdate event of the State Combo Box.
|
| This page was last modified 11:38, 14 February 2012. This page has been accessed 6,463 times. Disclaimers |