Solved

Clear filter from report after preview/print action

Posted on 2009-04-10
6
798 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
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)

 
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

Backup Your Microsoft Windows Server®

Backup 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.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now