473,383 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to synchronize 2 combo boxes to filter data in 2nd depending on value in 1st ?

Hello everybody
Thanks to Mr Lysander who guided me in building my data base. I have tried to synchronize two combo boxes named “Province” and “City” by method provided in Access Help so that I could filter the entries of ‘City’ when ‘Province’ were selected in “Province” combo box but I did not succeed.
I have got Table “City” with fields ‘City ID’, ‘ProvinceID’ (Linked with ID of Table “Province”) and ‘City’; and a Table “Province” with fields ‘ID’ and ‘Province’. In the form for data entry, I put the code in AfterUpdate property of “Province” following code;

Private Sub Province_AfterUpdate()

' Update the row source of the City combo box
' when the selection is made in the Province
' combo box.
Me.City.RowSource = "SELECT City FROM" & _
" City WHERE Province = " & Me.Province & _
" ORDER BY City"

Me.City = Me.City.ItemData(0)
End Sub

But I get an error. I derived this code from Access Help as given below;

Access Developer Reference
How to: Synchronize Two Combo Boxes on a Form
"This topic illustrates how to synchronize two combo boxes so that when you select an item in the first combo box, the selection limits the choices in the second combo box. For example, you may want the products displayed in a combo box to be limited to the category selected in another combo box.
In this example, the second combo box is filled with the results of an SQL statement. This SQL statement finds all the products that have a CategoryID that matches the category selected in the first combo box.
Whenever a category is selected in the first combo box, its AfterUpdate event procedure sets the second combo box's RowSourceType property. This refreshes the list of available products in the second combo box. Without this procedure, the contents of the second combo box would not change.
Private Sub cboCategories_AfterUpdate()

' Update the row source of the cboProducts combo box
' when the user makes a selection in the cboCategories
' combo box.
Me.cboProducts.RowSource = "SELECT ProductName FROM" & _
" tblProducts WHERE CategoryID = " & Me.cboCategories & _
" ORDER BY ProductName"

Me.cboProducts = Me.cboProducts.ItemData(0)
End Sub
"

Can anybody help me out solve this issue???
Feb 27 '11 #1
1 4505
beacon
579 512MB
Hi Yousaf,

Do you have a fields in your City and Province tables called City and Province or are the fields CityID and ProvinceID?

If you don't have a field called City in your City table or a field called Province in your Province table, then I think the problem lies with the SQL query you're using for the row source of the combo box. Instead of:
Expand|Select|Wrap|Line Numbers
  1. Me.City.RowSource = "SELECT City FROM" & _
  2. " City WHERE Province = " & Me.Province & _
  3. " ORDER BY City"
  4.  
...it should be this:
Expand|Select|Wrap|Line Numbers
  1. Me.City.RowSource = "SELECT CityID FROM" & _
  2. " City WHERE ProvinceID = " & Me.Province & _
  3. " ORDER BY CityID"
  4.  
Hope this helps and good luck,
beacon
Feb 27 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jeff Smith | last post by:
Hi This is a repost due to no responses Here's a problem I've encountered with Access 2003 which has got me to redesign how I get the row source in a second combo box using the first combo...
4
by: Chuckles | last post by:
Hi all, I have two unbound combo boxes on a form that I wuould like to use to delete a record from a table. The two combo boxes find data from two other tables through queries. When clicking on a...
0
by: cognoscento | last post by:
I'm currently putting together a database for my work (not an expert by any stretch, so muddling through as best as I can... you know the story...) and I could use some advice and hand-holding ...
4
by: tlyczko | last post by:
I read about limiting combo boxes' list data, for example, limiting the list of values in the second combo based on values in the first combo, and I found the Dev Ashish site link. I have two...
2
by: bmdavis | last post by:
Hi, On my form I have one field of "City", and this in turn needs to effect "Township". When township is selected, the next field is distance, and for every 'township' there are 2 distances...
5
by: consonanza | last post by:
I am working on a report filter form. It has 2 combo boxes (cmboSelectSubject and cmboSelectCategory) to select criteria. Selecting an entry in combo 1 restricts the options available in combo 2....
15
by: jonosborne | last post by:
hi, i hope someone can help, i have read a lot of tutorials relating to this matter but im afraid VBA isnt my strong point and i just need a touch of guidance. I have one table called which has...
6
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
12
by: micarl | last post by:
How would i print a report based on criteria selected from several Combo Boxes as well as multiple Multi Select List Boxes, that are located on the same form? I can get one Multi List Box, just...
3
by: tasawer | last post by:
Hi, I have an accident claims form that I need to requery on one of three different fields. Primary field is AccidentID ClientName (Can appear on more than one AccidentID) SolicitorsRef...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.