Solved

Clear filter from report after preview/print action

Posted on 2009-04-10
6
808 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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