Filter Subform from Parent Form
I have a subform inside a parent form. The subform shows up as a datasheet inside the parent form. I have two comboboxes in the parent form. When the user chooses a value from the combobox the subform should get filtered according to those two values.
The following is the code I used. It opens up another window and shows the filtered values instead of showing it within the parent subform.
Dim stDocName As String Dim stLinkCriteria As String stDocName = "3_Properties" stLinkCriteria = "[Program_Name]=" & "'" & Me![Combo2] & "'" DoCmd.OpenForm stDocName, , , stLinkCriteria
You can take advantage of link child and master fields to filter the subform without using any code. You can set the link master fields for your subform to the name of the combobox controls and the child fields to the relevant related columns (fields). Separate each entry with a semi-colon.
You can also set the record source of the subform at run time.
sSQL = "SELECT BText FROM Table WHERE AText = '" & Me.MyCombo & "'" Me.MySubformControlName.Form.Recordsource = sSQL