I have created a form hoping to give the user the option filter a report. The form has list boxes to select options, a filter button and a clear button. In the bottom of the form I added the subreport so it can update based on the filter criteria. How can I call out the subreport in the code so it filters? It works if I do it directly on the report with Report![List]
but it wont update on the form subreport. I'm also not getting all the records showing when filtered because records that have one of the two criteria blank won't appear due to the If Len(strSubsystem) = 0 Then strSubsystem = "Like '*'"
statement. Is there another statement I can use besides "like '*'"
to have all records show.
Here's the code
Private Sub cmdApplyFilter_Click()
Dim varItem As Variant
Dim strSubsystem As String
Dim strStatus As String
Dim strFilter As String
' Build criteria string from subsystem listbox
For Each varItem In Me.lstSubsystems.ItemsSelected
strSubsystem = strSubsystem & ",'" & Me.lstSubsystems.ItemData(varItem) _
& "'"
Next varItem
If Len(strSubsystem) = 0 Then
strSubsystem = "Like '*'"
Else
strSubsystem = Right(strSubsystem, Len(strSubsystem) - 1)
strSubsystem = "IN(" & strSubsystem & ")"
End If
' Build criteria string from status listbox
For Each varItem In Me.lstStatus.ItemsSelected
strStatus = strStatus & ",'" & Me.lstStatus.ItemData(varItem) _
& "'"
Next varItem
If Len(strStatus) = 0 Then
strStatus = "Like '*'"
Else
strStatus = Right(strStatus, Len(strStatus) - 1)
strStatus = "IN(" & strStatus & ")"
End If
' Build filter string
strFilter = "[Subsystem] " & strSubsystem & _
" AND [Status] " & strStatus
' Apply the filter and switch it on
With Forms![Filter]
.Filter = strFilter
.FilterOn = True
End With
End Sub