Report Filters

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top