THis is untested, but it is very similar to what I sometimes do. Normally, I would not be using combos on a bound form. I would have a subform dependent on the combo and the combo placed on an unbound form.
I would declare a couple of string variables in the header of the form.
Dim strSQL as string
Dim strWhere as string
Dim strCombo1 as string
Dim strCombo2 as string
Placing this at the very top of the module will cause the variables to be available everywhere in the form.
In the forms load event I would place the following code. This represents the primary key field name for a table "FieldPK > 0. The idea is to start your strWhere with something that will always return all records.
Code:
strCombo1 = ""
strCombo2 = ""
strWhere = "FieldPK > 0"
strSQL = "SELECT MyQry.* " & _
"FROM MyQry " & _
"WHERE " & strWhere & _
"ORDER BY [FieldPK];"
Me.RecordSource = strSQL
With this we can add to the strWhere using afterupdate events for the combos. and reasign the form's recordset.
In one combo afterupdate you could use something like this
Code:
'Reset strWhere
strWhere = "FieldPK > 0"
strCombo1 = "[SomeField] = " & Me.Combo1
strWhere = (strWhere & " AND " & strCombo2 & " AND ") & strCombo1
strSQL = "SELECT MyQry.* " & _
"FROM MyQry " & _
"WHERE " & strWhere & _
"ORDER BY [FieldPK];"
Me.RecordSource = strSQL
Then in the other combo afterupdate you want to switch the order of the variables for the combos.
Code:
'Reset strWhere
strWhere = "FieldPK > 0"
'strCombo2 = "[SomeField] = '" & Me.Combo2 & "'" Text version
strCombo2 = "[SomeField] = " & Me.Combo2 'Number version
Me.Combo2
strWhere = (strWhere & " AND " & strCombo1 & " AND ") & strCombo2
strSQL = "SELECT MyQry.* " & _
"FROM MyQry " & _
"WHERE " & strWhere & _
"ORDER BY [FieldPK];"
Me.RecordSource = strSQL
If your combos are text value then the code would have to change a little. We would have to concatenate StrCombo a little differently. If the combo values are numeric we could use maybe a long integer data type variable instead of string.