Solved

Clear filter from report after preview/print action

Posted on 2009-04-10
6
804 Views
Last Modified: 2013-11-28
I have multiple list boxes on a form. Each list box is set to multiselect. I am using VBA to capture the users selections from the list boxes and am using this to filter a report. It all works fine except occasionally the filter remains active with the report and so shows prior selections. I want to automatically reset the filter after the report has been previewed or printed.

I have tried multiple methods and all seem to have unintended and adverse consequences.

Am looking for some suggestions. A code snippet showing the creation of the filter string.

Thanks!

' Report will not filter if open, so make sure it is closed
    If CurrentProject.AllReports(strDoc).IsLoaded Then
        DoCmd.close acReport, strDoc
    End If
 
' This section determines what option the user has selected from the print option group.
' based upon the user selection, it will either Preview, Print or Export to Excel
'========================================================================================
 
 If Print_Company_Product_Support.Value = 2 And PrintReport_OptionGroup.Value >= 1 And Len(strWhere) <= 0 Then ' If the select criteria is enabled and the user is trying to print then check that values have been selected
        
    MsgBox "Please Select A Value From One of the Dropdown Boxes", vbInformation, "No Filter Criteria Selected!"
     
     Else
        intOptionValue = PrintReport_OptionGroup.Value ' Set variable to the Option group value
 '       MsgBox intOptionValue ' Display Option variable for TESTING purposes
        Select Case intOptionValue   ' Go through case options and act based upon its value
            Case 1   ' if preview report is selected then preview
            
                ' This is a temporary message while I figure out how to preview such a large report
                MsgBox "This feature is not yet working due to the size of the report"
  
  '               DoCmd.OpenReport strDoc, acViewPreview, , strWhere
   '              Reports(strDoc).FilterOn = True
'-----
    ' case 2 not yet setup
        
            Case 3  ' if Export report is selected then export to Excel
                   DoCmd.OpenReport strDoc, acViewPreview, , strWhere, acIcon
                   Reports(strDoc).FilterOn = True
                   RunCommand acCmdOutputToExcel
                   DoCmd.close acReport, strDoc
        End Select
        
   End If
    
 '========================================================================================
   
 
Exit_Handler:
    Exit Sub
 
Err_Handler:
    If Err.Number <> 2501 Then  'Ignore "Report cancelled" error.
        MsgBox "Error " & Err.Number & " - " & Err.Description, , "cmdPreview_Click"
    
        ElseIf Err.Number = 2451 Then
        ' Ignore error and reset
         Err.Clear
    End If
    
    Resume Exit_Handler
 
End Sub

Open in new window

0
Comment
Question by:dglover
  • 4
  • 2
6 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24120799
dglover,

If your ultimate question is how to clear the listboxes, then use code like this after your Preview/Print command code:

Dim ctl As Control

For Each ctl In Me.Controls
    If ctl.ControlType = acListBox Then
        ctl = ""
    End If
Next ctl


JeffCoachman
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24120800
Something like this:

Sub YourCode()
Dim ctl As Control

    'YourCode
    'Your Print/PreviewCode
    For Each ctl In Me.Controls
        If ctl.ControlType = acListBox Then
            ctl = ""
        End If
    Next ctl

'...

End Sub
0
 

Author Comment

by:dglover
ID: 24122227
Thanks for the response. I can see how your suggestion would work well to clear the list boxes. My problem doesn't seem to be with the listboxes. It appears to be that the filter that was assigned to the report occasionally isn't removed from the report "filter" control. I don't use VBA all that much so I may be missing the point but I don't see how clearing the list boxes will also make sure the report filter box is cleared.
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 250 total points
ID: 24123465
"I don't see how clearing the list boxes will also make sure the report filter box is cleared."
You stated listboxes in your original question.

My thought was that the "Filter" took it's value from the lisbox.
Hence it\f the list box was claeaed, so to would be the filter.

If all you need to do is clear the filter, use this after your code to Preview print the report:

    Me.Filter=""
    Me.FilterOn=False
    Me.Requery

JeffCoachman
0
 

Author Comment

by:dglover
ID: 24123903
Great! That seems to work.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24124024
;-)
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question