1. Create 3 queries:
a) Qry_Combo_Branch
Name:
Qry_Combo_Branch
SQL:
Code:
SELECT Branch.[Branch ID], Branch.Branch
FROM Branch
ORDER BY Branch.Branch
UNION SELECT 0, ' <All>'
FROM Branch;
b) Qry_Combo_Department
Name:
Qry_Combo_Department
SQL:
Code:
SELECT Department.[Department ID], Department.Department
FROM Department
ORDER BY Department.Department
UNION SELECT 0, ' <All>'
FROM Department;
c) Qry_Combo_Locationt
Name:
Qry_Combo_Location
SQL:
Code:
SELECT Location.[Location ID], Location.Location
FROM Location
ORDER BY Location.Location
UNION SELECT 0, ' <All>'
FROM Location;
2. Add 3 combo boxes to the form (also works with list boxes):
a) Combo_Branch
Name:
Combo_Branch
Row Source Type:
Table/Query
Row Source:
Qry_Combo_Branch
Bound Column:
1
Column Count:
2
Column Width:
0cm;3cm (convert into inches if necessary)
After Update:
=SetFilter()
b) Combo_Department
Name:
Combo_Department
Row Source Type:
Table/Query
Row Source:
Qry_Combo_Department
Bound Column:
1
Column Count:
2
Column Width:
0cm;3cm (convert into inches if necessary)
After Update:
=SetFilter()
c) Combo_Location
Name:
Combo_Location
Row Source Type:
Table/Query
Row Source:
Qry_Combo_Location
Bound Column:
1
Column Count:
2
Column Width:
0cm;3cm (convert into inches if necessary)
After Update:
=SetFilter()
3. Add this function in the Form Class module:
Code:
Private Function SetFilter()
Dim strFilter As String
If Me.Combo_Branch.value <> 0 Then
strFilter = "[Branch ID] = " & Me.Combo_Branch.value
End If
If Me.Combo_Department <> 0 Then
If Len(strFilter) > 0 Then strFilter = strFilter & " AND "
strFilter = strFilter & "[Department ID] = " & Me.Combo_Department.value
End If
If Me.Combo_Location <> 0 Then
If Len(strFilter) > 0 Then strFilter = strFilter & " AND "
strFilter = strFilter & "[Location ID] = " & Me.Combo_Location.value
End If
If Len(strFilter) > 0 Then
Me.Filter = strFilter
Me.FilterOn = True
Else
Me.FilterOn = False
End If
End Function