Hello! first time long time.
Anywho, I have a Report section, taken and modified from the Northwind sample. It uses comboboxes and option buttons to apply a filter to a subform, and then pushes the filter to the report. That all works fine.
However, in the subform, when you click on a field and use the common filter options (clicking the filter button in the Access navigation menu, or right clicking in the field and selecting a filter option from the menu), it won't apply that filter alongside the coded filters when pushing to a report. I'm sure it's as simple as adding a line to include any current filter, but I'm a novice at code and have been stumped trying to find an answer online.
I have pasted the code below. I have tried a few variations of adding Me.Filter and Me.FilterOn = True, etc... to no success. Any help would be greatly appreciated:
Anywho, I have a Report section, taken and modified from the Northwind sample. It uses comboboxes and option buttons to apply a filter to a subform, and then pushes the filter to the report. That all works fine.
However, in the subform, when you click on a field and use the common filter options (clicking the filter button in the Access navigation menu, or right clicking in the field and selecting a filter option from the menu), it won't apply that filter alongside the coded filters when pushing to a report. I'm sure it's as simple as adding a line to include any current filter, but I'm a novice at code and have been stumped trying to find an answer online.
I have pasted the code below. I have tried a few variations of adding Me.Filter and Me.FilterOn = True, etc... to no success. Any help would be greatly appreciated:
Code:
Private Function StockSearch()
On Error GoTo Error_StockSearch
Dim FilterClause As String, D As Long
Const strcJetDate = "\#mm\/dd\/yyyy\#" 'Do NOT change it to match your local settings
Dim strDateField As String
strDateField = "[pay run]" 'Put your field name in the square brackets in these quotes
'Hold whether we Use AND or OR in our Filter Criteria
D = Me.DirectionGrp.Value
'Filter by Option Group Selected
If Me.PriorityGrp.Value = 5 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[SumRequested] Is Not Null"
End If
If Me.PriorityGrp.Value = 6 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[SumRequested] Is Null"
End If
'1st Combo - Fiscal Year Text DataType
If Nz(Me.cboFY.Column(0), 0) > 0 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[Fiscal Year]='" & Me.cboFY.Value & "'"
End If
'2nd Combo - REGION Text DataType
If Nz(Me.cboRegion.Column(0), 0) > 0 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[Region]='" & Me.cboRegion.Value & "'"
End If
'3rd Combo - DIR Text DataType
If Nz(Me.cboDIR.Column(0), 0) > 0 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[DIR]='" & Me.cboDIR.Value & "'"
End If
'4th Combo - BRANCH Text DataType
If Nz(Me.cboBranch.Column(0), 0) > 0 Then
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
FilterClause = FilterClause & "[Branch]='" & Me.cboBranch.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]![ReportCenter]![sfrReportPage].[Form]![srpReport].Form.Filter = CurrentFilter
'Turn on the Filter
[Forms]![ReportCenter]![sfrReportPage].[Form]![srpReport].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
Private Sub StockReportBut_Click()
On Error GoTo Err_StockReport_Click
DoCmd.OpenReport "rpt_Costs_by_Employee", acPreview, , CurrentFilter
Exit_StockReport_Click:
Exit Sub
Err_StockReport_Click:
MsgBox Err.Description
Resume Exit_StockReport_Click
End Sub