Resetting the form filter filter for a new report

F

Frank Tempelman

Hi all,

I have a database with about 350 records in it. I created a form
showing a list of these, with their most important attributes. Now I
can use the form's standard 'Filter by Selection' to show only the
records with a certain value for an attribute. So far, so good.

I also created a report. Clicking on the 'report' button on my form
prints the filtered records, and if no filter is applied, it prints
all records. Clicking the button activates the following procedure:

Private Sub Report_Click()
On Error GoTo Err_Report_Click

' get the list of IDs from the form's Recordset
Dim strFilter As String
strFilter = Me.Filter
DoCmd.OpenReport "rptRequirementList", , , strFilter

Exit_Report_Click:
Exit Sub

Err_Report_Click:
MsgBox Err.Description
Resume Exit_Report_Click

End Sub

and this all works very nicely. Except for a slight problem: if I
remove the filter (by right-clicking on the form and choosing 'Remove
Filter/Sort') the appropriate complete set of records is shown again.
But if I want to print all records now by clicking the report button,
in the report the old filter is still applied! If I want to print all
records before having applied a filter, everything is ok.

Can't find the solution. Should I additionally reset the filter
somewhere in the code, and how?

TIA

Frank Tempelman
 
D

Dirk Goldgar

Frank Tempelman said:
Hi all,

I have a database with about 350 records in it. I created a form
showing a list of these, with their most important attributes. Now I
can use the form's standard 'Filter by Selection' to show only the
records with a certain value for an attribute. So far, so good.

I also created a report. Clicking on the 'report' button on my form
prints the filtered records, and if no filter is applied, it prints
all records. Clicking the button activates the following procedure:

Private Sub Report_Click()
On Error GoTo Err_Report_Click

' get the list of IDs from the form's Recordset
Dim strFilter As String
strFilter = Me.Filter
DoCmd.OpenReport "rptRequirementList", , , strFilter

Exit_Report_Click:
Exit Sub

Err_Report_Click:
MsgBox Err.Description
Resume Exit_Report_Click

End Sub

and this all works very nicely. Except for a slight problem: if I
remove the filter (by right-clicking on the form and choosing 'Remove
Filter/Sort') the appropriate complete set of records is shown again.
But if I want to print all records now by clicking the report button,
in the report the old filter is still applied! If I want to print all
records before having applied a filter, everything is ok.

Can't find the solution. Should I additionally reset the filter
somewhere in the code, and how?


Just check to see if the filter is currently applied or not:

If Me.FilterOn Then
strFilter = Me.Filter
Else
strFilter = vbNullString
End If

DoCmd.OpenReport "rptRequirementList", , , strFilter
 
F

Frank Tempelman

Just check to see if the filter is currently applied or not:

    If Me.FilterOn Then
        strFilter = Me.Filter
    Else
        strFilter = vbNullString
    End If

    DoCmd.OpenReport "rptRequirementList", , , strFilter

Thanks! Great!

Frank
 
F

Frank Tempelman

Thanks! Great!

Frank

Well, I said 'Thanks', and I still mean it... bu the solution does not
work! The old filter is still present when re-opening the report
without a filter...
 
D

Dirk Goldgar

I can't reproduce this problem, and I can't see how it can possibly be,
given the code that I posted. Are you sure you don't have code in the
report itself, or some other code besides that in the button, that imposes
the filter on the report?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Thanks! Great!

Frank

Well, I said 'Thanks', and I still mean it... bu the solution does not
work! The old filter is still present when re-opening the report
without a filter...
 

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