I have Access 2010. I have a continuous form. I have one combo box (cbo_BranchSearch) that filters my form
Private Sub cbo_BranchSearch_AfterUpdate()
If Me.cbo_BranchSearch & "" <> "" Then
Me.Filter = "[PriKey] = " & Me.cbo_BranchSearch
Else
Me.Filter = ""
End If
Me.FilterOn = True
Me.cbo_LocationUser.Requery
End Sub
I have a second combo box (cbo_LocationUser) that's rowsource is similar to the first cbo pointing to my query qry_ElistSearch, in which the form gets its data.
The first cbobox works great. Now I would like the second cbo to be filtered based on what I selected on the first cbo. Then when I see those, it would then filter my continuous form from my selection on the second. I am sure this question is asked many times. But I think I am not phrasing the question right on my search so my apologies. Thanks you so much. It has been awhile since I used VBA. Any help is much appreciated.
Todd
There are several methods. The one I use involves adding criteria to the RowSource query and one line of code to the AfterUpdate event of the "parent" combo.
The RowSource query for combo2 would be:
Select ...
From ...
Where SomeField = Forms!yourform!yourcombo1;
Then in the AfterUpdate event of combo1:
Me.Combo2.Requery
To include a third combo:
The RowSource query for combo3 would be:
Select ...
From ...
Where SomeField = Forms!yourform!yourcombo2;
Then the AfterUpdate event of combo2:
Me.Combo3.Requery
And finally, to filter the form - I never use filters because I almost always use non-Jet/ACE back end databases. Filters assume the ENTIRE recordset is local and is used to reduce what you actually see presented in the form. Instead, I use criteria in the query itself. This is far superior when working with remote databases since it limits the data that is retrieved rather than retrieving everything and hiding some of it.
So your RecordSource query would be:
Select ...
From ...
Where somefield = Forms!yourform!combo1 AND somefield2 = Forms!yourform!combo2;
Then you need to Requery the form. You can do this with a button (my preference when there is more than one selection field involved) or by using the AfterUpdate event of the "rightmost" field.
Me.Requery