i have searched the forum and found this example similar to what i am trying to achieve.
http://www.access-programmers.co.uk/forums/showthread.php?t=157601
i have a search form (consignment Search) with 5 combo boxes i would like to use to filter a subform (Consignments Details). I have copied and paste the example from the forum however the filter does not seem to work. any assistance would be greatly appreciated. A copy of my database is attached.
Private Function StockSearch()
On Error GoTo Error_StockSearch
Dim FilterClause As String, D As Long
'Hold whether we Use AND or OR in our Filter Criteria
D = Me.DirectionGrp.Value
'1st Combo - Container number - Assuming the Table Field 'Grade' is of a Text DataType
If Nz(Me.Container_Number.Column(0), 0) > 0 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[Container_Number]='" & Me.Container_Number.Value & "'"
End If
'2nd Combo - Order Number - Assuming the Table Field 'Treatment' is of a Text DataType
If Nz(Me.Order_Number.Column(0), 0) > 0 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[Order_Number]='" & Me.Order_Number.Value & "'"
End If
'3rd Combo - Job Number - Assuming the Table Field 'Location' is of a Text DataType
If Nz(Me.Job_number.Column(0), 0) > 0 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[Job_Number]='" & Me.Job_number.Value & "'"
End If
'4th Combo - Product Value - Assuming the Table Field 'Drying' is of a Text DataType
If Len(Me.Product.Value & "") > 0 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[Product]='" & Me.Product.Value & "'"
End If
'5th Combo - Discharge Port - Assuming the Table Field 'Finish' is of a Text DataType
If Len(Me.Discharge_Port.Value & "") > 0 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[Discharge_Port]='" & Me.Discharge_Port.Value & "'"
End If
'Fill this Form wide variable so that it can be used for
'the Report.
CurrentFilter = FilterClause: FilterClause = ""
'Place our created Filter Criteria into the Filter property of SubForm.
Forms("Consignment Search")("Consignments Details").Form.Filter = CurrentFilter
'Turn on the Filter
Forms("Consignment Search")("Consignments Details").Form.FilterOn = True
Exit_StockSearch:
Exit Function
Error_StockSearch:
MsgBox "StockSearch Function Error" & vbCr & vbCr & _
Err.Number & " - " & Err.Description, vbExclamation, _
"Stock Search Error"
Resume Exit_StockSearch
End Function
http://www.access-programmers.co.uk/forums/showthread.php?t=157601
i have a search form (consignment Search) with 5 combo boxes i would like to use to filter a subform (Consignments Details). I have copied and paste the example from the forum however the filter does not seem to work. any assistance would be greatly appreciated. A copy of my database is attached.
Private Function StockSearch()
On Error GoTo Error_StockSearch
Dim FilterClause As String, D As Long
'Hold whether we Use AND or OR in our Filter Criteria
D = Me.DirectionGrp.Value
'1st Combo - Container number - Assuming the Table Field 'Grade' is of a Text DataType
If Nz(Me.Container_Number.Column(0), 0) > 0 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[Container_Number]='" & Me.Container_Number.Value & "'"
End If
'2nd Combo - Order Number - Assuming the Table Field 'Treatment' is of a Text DataType
If Nz(Me.Order_Number.Column(0), 0) > 0 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[Order_Number]='" & Me.Order_Number.Value & "'"
End If
'3rd Combo - Job Number - Assuming the Table Field 'Location' is of a Text DataType
If Nz(Me.Job_number.Column(0), 0) > 0 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[Job_Number]='" & Me.Job_number.Value & "'"
End If
'4th Combo - Product Value - Assuming the Table Field 'Drying' is of a Text DataType
If Len(Me.Product.Value & "") > 0 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[Product]='" & Me.Product.Value & "'"
End If
'5th Combo - Discharge Port - Assuming the Table Field 'Finish' is of a Text DataType
If Len(Me.Discharge_Port.Value & "") > 0 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[Discharge_Port]='" & Me.Discharge_Port.Value & "'"
End If
'Fill this Form wide variable so that it can be used for
'the Report.
CurrentFilter = FilterClause: FilterClause = ""
'Place our created Filter Criteria into the Filter property of SubForm.
Forms("Consignment Search")("Consignments Details").Form.Filter = CurrentFilter
'Turn on the Filter
Forms("Consignment Search")("Consignments Details").Form.FilterOn = True
Exit_StockSearch:
Exit Function
Error_StockSearch:
MsgBox "StockSearch Function Error" & vbCr & vbCr & _
Err.Number & " - " & Err.Description, vbExclamation, _
"Stock Search Error"
Resume Exit_StockSearch
End Function