W
Wendy
I used the code from this website and it works fine unless there are null
values in one or more of the fields I'm using in the filter. If one of the
fields is null for a particular record, and the other fields in that record
meet the chosen criteria, I want the record to be returned in the report. In
other words, the I'm trying for is something like: if Cateogry = "cosmetics"
AND (Region like * OR Region is Null), then....But I don't know how to
translate this into the correct syntax for the filter statement. Can anyone
help with the code I would need to add to ignore the nulls?
Thank you!
Here's my current code:
Private Sub CmdApplyCriteria_Click()
Dim strCategory As String
Dim strRegion As String
Dim strReportYr As String
Dim strFilter As String
If IsNull(Me.cboCategory.Value) Then
strCategory = "Like '*'"
Else
strCategory = "='" & Me.cboCategory.Value & "'"
End If
If IsNull(Me.cboRegion.Value) Then
strRegion = "Like '*' "
Else
strRegion = "='" & Me.cboRegion.Value & "'"
End If
If IsNull(Me.cboReportYr.Value) Then
strReportYr = "Like '*' "
Else
strReportYr = "='" & Me.cboReportYr.Value & "'"
End If
strFilter = "[Category] " & strCategory & " AND [Region] " & strRegion & "
AND [ReportYr] " & strReportYr
With Reports![Product Report]
.Filter = strFilter
.FilterOn = True
End With
End Sub
values in one or more of the fields I'm using in the filter. If one of the
fields is null for a particular record, and the other fields in that record
meet the chosen criteria, I want the record to be returned in the report. In
other words, the I'm trying for is something like: if Cateogry = "cosmetics"
AND (Region like * OR Region is Null), then....But I don't know how to
translate this into the correct syntax for the filter statement. Can anyone
help with the code I would need to add to ignore the nulls?
Thank you!
Here's my current code:
Private Sub CmdApplyCriteria_Click()
Dim strCategory As String
Dim strRegion As String
Dim strReportYr As String
Dim strFilter As String
If IsNull(Me.cboCategory.Value) Then
strCategory = "Like '*'"
Else
strCategory = "='" & Me.cboCategory.Value & "'"
End If
If IsNull(Me.cboRegion.Value) Then
strRegion = "Like '*' "
Else
strRegion = "='" & Me.cboRegion.Value & "'"
End If
If IsNull(Me.cboReportYr.Value) Then
strReportYr = "Like '*' "
Else
strReportYr = "='" & Me.cboReportYr.Value & "'"
End If
strFilter = "[Category] " & strCategory & " AND [Region] " & strRegion & "
AND [ReportYr] " & strReportYr
With Reports![Product Report]
.Filter = strFilter
.FilterOn = True
End With
End Sub