I'm trying to setup some cascading combo boxes built around a single table that has a many to many relationship through a "junction" table. A session or Class offering may have many locations and a location can have many class offerings, so I have created a junction table. This part has been easy and if I populate that junction table with test data I can run all the queries I want.
The big issue is the data input, so this is a form issue. I am trying to build a form that allows me to input the city for the location. I've successfully done this in a form based of the junction table in other subforms if it is just a single combo box. But, I need to have cascading combo boxes, because the location has to be filtered for ease of input. First by Country, then State, then the City.
I am putting all of this in a subform based on the junction table "CitySession"
The first combos' rowsource
SELECT DISTINCT [tblCity].Country FROM tblCity;
Then, to populate/filter the other combos
I've been able to utilize the after update events...
Private Sub cboCountry_AfterUpdate()
On Error Resume Next
cboState.RowSource = "Select DISTINCT tblCity.State " & _
"FROM tblCity " & _
"WHERE tblCity.Country = '" & cboCountry.Value & "' " & _
"ORDER BY tblCity.State;"
End Sub
Private Sub Combo6_AfterUpdate()
On Error Resume Next
cboCity.RowSource = "Select tblCity.CityUID, tblCity.City " & _
"FROM tblCity " & _
"WHERE tblCity.State = '" & cboState.Value & "' " & _
"ORDER BY tblCity.City;"
End Sub
Seems to me like it should work, but I get blank combo boxes, The state cbo populates after I select a blank field, and the city field shows up right away, but is not filtered at all. (the city combobox is the only one bound and it is bound to CityID). Also, when I select state, all the records above reflect whatever I just selected. I suppose this is due to not binding the boxes, but if I do bind the country and state combo boxes, I get "The Value you entered is not valid for this field.".
Is this a subform issue? It does populate my junction table and while I had the combo boxes working on their own form, I couldn't get it to populate the junction table. I need to populate that junction table somehow?
Come to my rescue. I'm not new to Access, but I've not done any development work in ten years and this little frustration has been going on for at least 4 days now! Ugh.... should have kept up my skills!:banghead:
The big issue is the data input, so this is a form issue. I am trying to build a form that allows me to input the city for the location. I've successfully done this in a form based of the junction table in other subforms if it is just a single combo box. But, I need to have cascading combo boxes, because the location has to be filtered for ease of input. First by Country, then State, then the City.
I am putting all of this in a subform based on the junction table "CitySession"
The first combos' rowsource
SELECT DISTINCT [tblCity].Country FROM tblCity;
Then, to populate/filter the other combos
I've been able to utilize the after update events...
Private Sub cboCountry_AfterUpdate()
On Error Resume Next
cboState.RowSource = "Select DISTINCT tblCity.State " & _
"FROM tblCity " & _
"WHERE tblCity.Country = '" & cboCountry.Value & "' " & _
"ORDER BY tblCity.State;"
End Sub
Private Sub Combo6_AfterUpdate()
On Error Resume Next
cboCity.RowSource = "Select tblCity.CityUID, tblCity.City " & _
"FROM tblCity " & _
"WHERE tblCity.State = '" & cboState.Value & "' " & _
"ORDER BY tblCity.City;"
End Sub
Seems to me like it should work, but I get blank combo boxes, The state cbo populates after I select a blank field, and the city field shows up right away, but is not filtered at all. (the city combobox is the only one bound and it is bound to CityID). Also, when I select state, all the records above reflect whatever I just selected. I suppose this is due to not binding the boxes, but if I do bind the country and state combo boxes, I get "The Value you entered is not valid for this field.".
Is this a subform issue? It does populate my junction table and while I had the combo boxes working on their own form, I couldn't get it to populate the junction table. I need to populate that junction table somehow?
Come to my rescue. I'm not new to Access, but I've not done any development work in ten years and this little frustration has been going on for at least 4 days now! Ugh.... should have kept up my skills!:banghead: