Solved

Limit Selection in a combo box

Posted on 1998-08-25
5
382 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2016 - query 23 60
Ms Access VBA Variables 6 27
Why can't I get rid of record selectors on my form? 9 28
Field naming convntions - MS Access 7 27
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

770 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