Solved

Clear filter from report after preview/print action

Posted on 2009-04-10
6
811 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

734 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