Programatically Removing Filter

G

Guest

I set up code which creates a filter based on user selection criterion and
then runs a report. As long as the user enters some criterion, the report
works. When the user enters no criterion, but there was criterion entered on
the last run, the report uses the last run criterion. The code is listed
below. The variable, strFilter contains the filter. If it is not equal to an
empty string the report is run with the filter, otherwise it is run without
it. I tried running the report using strFilter when it was an empty string,
but it did not remove the filter from the last run. Is there a way to do
this ?

If strFilter <> "" Then
DoCmd.OpenReport Me.cboReportType, acViewPreview, , strFilter
Else
DoCmd.OpenReport Me.cboReportType, acViewPreview
End If
 
M

Marshall Barton

rmcompute said:
I set up code which creates a filter based on user selection criterion and
then runs a report. As long as the user enters some criterion, the report
works. When the user enters no criterion, but there was criterion entered on
the last run, the report uses the last run criterion. The code is listed
below. The variable, strFilter contains the filter. If it is not equal to an
empty string the report is run with the filter, otherwise it is run without
it. I tried running the report using strFilter when it was an empty string,
but it did not remove the filter from the last run. Is there a way to do
this ?

If strFilter <> "" Then
DoCmd.OpenReport Me.cboReportType, acViewPreview, , strFilter
Else
DoCmd.OpenReport Me.cboReportType, acViewPreview
End If


The report should not save the filter. Check to see if you
have any code in the report (Close event?) that might be
sav8ing the form.

OTOH, if you are not closing the report before opening it
again, this behavior would be normal.
 
G

Guest

I was unable to find where the report was closing, so I tried putting a field
which existed on the report into the filter field when there was no filter
and it solved the issue:
If strFilter <> "" Then
DoCmd.OpenReport Me.cboReportType, acViewPreview, , strFilter
Else
DoCmd.OpenReport Me.cboReportType, acViewPreview, , "RptPeriod"
End If

Thanks.
 
M

Marshall Barton

That might mask the problem, but it won't fix anything.

The report's Close event (or maybe the Unload event) is
where you should look. It's not unheard of for people to
mistakenly use DoCmd.Save.

If you do not have a Close event procedure, try using it to
set the Filter to an empty string:

Me.Filter = ""
Me.FilterOn = False
 
G

Guest

Ok. I will try:
Me.Filter = ""
Me.FilterOn = False

Thank you.


Marshall Barton said:
That might mask the problem, but it won't fix anything.

The report's Close event (or maybe the Unload event) is
where you should look. It's not unheard of for people to
mistakenly use DoCmd.Save.

If you do not have a Close event procedure, try using it to
set the Filter to an empty string:

Me.Filter = ""
Me.FilterOn = False
--
Marsh
MVP [MS Access]

I was unable to find where the report was closing, so I tried putting a field
which existed on the report into the filter field when there was no filter
and it solved the issue:
If strFilter <> "" Then
DoCmd.OpenReport Me.cboReportType, acViewPreview, , strFilter
Else
DoCmd.OpenReport Me.cboReportType, acViewPreview, , "RptPeriod"
End If
 

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