Solved

Clear filter from report after preview/print action

Posted on 2009-04-10
6
815 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 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