Solved

Limit Selection in a combo box

Posted on 1998-08-25
5
384 Views
Last Modified: 2011-10-03
In my form, I wish to limit the selection in a combo box based on a value in another another combo box. The source of the data is a table which has two fields, SalesProv and SalesCity. What I want to happen is, when the user selects an entry in the SalesProv combo box, the selection of cities in the SalesCity combo box is limited to the cities belonging to that province.

Any ideas?

Thanks!
0
Comment
Question by:axxess
5 Comments
 

Accepted Solution

by:
JCreson earned 30 total points
ID: 1960299
I would try this:

    Since the first combo box contains the province, you want to use the AfterUpdate event to load the second combo box on the fly.  Use code to set the Row Source of the second combo box to a  query or SQL Statement, whichever way you feel more comfortable with, ("SELECT SalesCity from <tablename> WHERE SalesProv = '" & Combo1.Text & "') using the Text property of the first box as a parameter. Then requery the second box to load it up with the city data.  I think you'll get the idea...

0
 
LVL 1

Expert Comment

by:LostSoul
ID: 1960300
I always use the "On click" event rather that the "After Update" as it implies the action is triggered only after the data is saved to the table.  Anyways...

While JCreson's solution is acceptable, you must prepare for all contingencies.  For example, the user might want to put the city in before the province.  This should be expected as it is the "usual" order of address entry.  To allow for this, as users hate being told how to do things by a computer, is to allow the list of cities to contain ALL cities, then have it filtered once a province is selected so, for example, if the user picks "Toronto" then picks "Newfoundland" the "Toronto" selection is changed to a null.


0
 
LVL 5

Expert Comment

by:tuvi
ID: 1960301
Also, prepare for users who enter new province and new city that are not in the list.
0
 

Expert Comment

by:JCreson
ID: 1960302
Sorry folks...was only looking at the basic problem at hand, not application wide. You both are correct and I thank you for commenting so quickly.
0
 

Author Comment

by:axxess
ID: 1960303
JC: Thanks, but I'm rather new to VBA. Appreciate details of your solution re "using code to set the RowSource...requery to load City data..". Thanks as well for the helpful comments(Tuvi,LostSoul).
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question