Cascading Combo Boxes

behdad

New member
Local time
Today, 08:37
Joined
Nov 28, 2011
Messages
2
I was wandering if anyone could help me with Microsoft Access Cascading Combo Boxes? Basically I have Region, District and Ward for Tanzania. I want them to cascade to each other in the table (UJANA) so you can select a region and only be able to populate the district and wards that are in the selected region.
I have uploaded the database so you can take a look and see why it is not working.

Thank you!
 

Attachments

I have added a form to your database that demonstrates how to use cascading combo boxes as you indicated you want them to work.

The only table that is required to make this work is the "TZ_Wards" table. Look at the "Name" for each combo box. Take a look at the record source for each of the combo boxes. The "cboDistrict" combo box uses the selected value in the "cboRegion" combo box as the criteria for it's records. The same is true for the "cboWard" combo box.

Then also look at the small amount of VBA code in the After Update event of the "cboRegion" and "cboDistrict" combo boxes. One requirement is that when a selection is made from a combo box, each subsequent dependent combo box must be re-queried so then will be filtered correctly.
 

Attachments

Hi

In addition to the suggestion from Mr B, I would add a line of code before each requery, that sets the value of the combo box that is being requeried to a zero length string. Something like
Code:
Me.ComboBoxName = ""
 
enable or disable combo box

Hi

Glad to be on this forum. Can some help me... I've 2 combo box on my form , 1)status 2)refer reason. What i want is when the form loads the refer combo should be disabled and it should only be enabled when i select "refer to tl" from the status combo box, any help thanks....
 
Hi Janith,

For future reference it is best to create a new thread when asking a new question, that way you will get the best advice.

Firstly you will need to set the enabled property of the refer combobox to false, so that it is disabled when the form is opened.

I have assumed here that the refer combobox has a valid selection if the combobox value is not null. There are other ways you could validate this.

Then I would add some code to the AfterUpdate event of the status combobox, e.g.

Code:
Private Sub StatusComboboxName_AfterUpdate()
    Me!ReferComboboxName.Enabled = Not IsNull(Me!StatusComboboxName)
End Sub
 
Hi Spark80, Thank you for the response. but I also want to insure that the refer combo box is only enabled when a value "refer to TL" is selected from status combo box. I 'm sorry that it was not evident from my query... thank you
 
Try this:
Code:
Private Sub StatusComboboxName_AfterUpdate()
    If Me!StatusComboboxName = "refer to TL" Then
       Me!ReferComboboxName.Enabled = True
    Else
       Me!ReferComboboxName.Enabled = False
    End If
 
End Sub
 
Hi

My dear friends, thank you one and all for the prompt response you have given. gud news is I was able to achieve this on another system and with that bit of confidence I managed to figure the problem as well...

Next time I've a doubt I now know where to look for ...
 

Users who are viewing this thread

Back
Top Bottom