This is code to run a filter on a report using two multi-select list boxes. It was working fine before, and then I changed the [FY] or fiscal year data in all associated tables from text to number, and now it won't work. The debug stop on the highlighted line, not sure what that means.
Let me preface this by saying I know very little about code and I received help to put this together.
Thanks for any help
Let me preface this by saying I know very little about code and I received help to put this together.
Code:
Private Sub cmdApplyFilter_Click()
Dim varItem As Variant
Dim strYear As String
Dim strBrand As String
Dim strFilter As String
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "Inventory$Crosstab v4") <> acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Build criteria string from lstYear listbox
For Each varItem In Me.lstYear.ItemsSelected
strYear = strYear & ",'" & Me.lstYear.ItemData(varItem) _
& "'"
Next varItem
If Len(strYear) = 0 Then
strYear = "Like '*'"
Else
strYear = Right(strYear, Len(strYear) - 1)
strYear = "IN(" & strYear & ")"
End If
' Build criteria string from lstBrand listbox
For Each varItem In Me.lstBrand.ItemsSelected
strBrand = strBrand & ",'" & Me.lstBrand.ItemData(varItem) _
& "'"
Next varItem
If Len(strBrand) = 0 Then
strBrand = "Like '*'"
Else
strBrand = Right(strBrand, Len(strBrand) - 1)
strBrand = "IN(" & strBrand & ")"
End If
' Build filter string
strFilter = " [Brand] " & strBrand & _
" AND [FY] " & strYear
' Apply the filter and switch it on
With Reports![Inventory$Crosstab v4]
.Filter = strFilter
[COLOR=Red][B] .FilterOn = True[/B][/COLOR]
End With
End Sub
Private Sub cmdRemoveFilter_Click()
On Error Resume Next
' Switch the filter off
Reports![Inventory$Crosstab v4].FilterOn = False
End Sub
Last edited: