Forum Discussion
Error in cascading Combo Boxes
- Jul 17, 2024
Hi XPS35, thank you for your help, I think I'm on the right path!
cobStatus now presents only the choices in the 'Status' field of the data source that are available for the selected country! However, this happens when, after selecting the country I go and try to select the Status:
The system asks me to re-enter the country manually.
1. How do I eliminate that error? and
2. How can I filter the two other combo boxes based on choices made in the first two? What would the After Update event look like for Concept and Project Type?
Thank you so much for your help!
Gilmour10 , you do not need [Tables]![Project Database] on your query string.
the name of the table is enough.
also country table have no relationship with status table.
Hi arnel_gp,
Tried your script and got a bunch of errors, probably due to syntax issues. Unfortunately, with my very limited VBA skills, I can't figure out what's wrong with it and make corrections. The script you provided me with is as follows:
Private Sub cobCountry_AfterUpdate() Call subUpdateRowSource() End Sub Private sub cobStatus_AfterUpdate() call subUpdateRowSource() End Sub Private Sub subUpdateRowSource() Dim strSQL As String Dim strWhere As String strSQL = "SELECT [Project Database].[Project Stage] " & _ "FROM [Project Database]" If Me.cobCountry.ListIndex > -1 Then strWhere = strWhere & "[Country] = '" & Me.[cobCountry] & "' And " End If If Me.cobStatus.ListIndex > -1 Then strWhere = strWhere & "[Status] = '" & Me.[cobStatus] & "' And " End If If Len(strWhere)<>0 Then strWhere=Left$(strWhere, Len(strWhere)- 5) strSQL=strSQL & " WHERE " & strWhere End If Me.cobStatus.RowSource = strSQL End Sub
Which you said I should add to the form... What do you mean by that? Assign it to a button or to each combo box?
I realize this is way above my skill level and may require a lot of back and forth. I understand if you decline to respond. Thank you for your help so far!