Results 1 to 4 of 4
  1. #1
    TOPSie is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    108

    Save Report as PDF - Filter not working

    This is driving me mad. In some inherited code are lots of examples of saving reports as PDF files, prior to emailing them.
    So I have copied working code and changed it for an existing report:

    Code:
    If gMessage = "Option1" Then    DoCmd.OpenReport "repPaymentHistory", acViewPreview, , "customerid=" & intCustomerID & "", acDialog
    Else
    
    
        gEmailMessage = "Please see attached Payment History Report"
        strFolder = Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name)))
        strFile = "PaymentHistory.pdf"
        strPath = strFolder & strFile
        DoCmd.OpenReport "repPaymentHistory", acPreview, , , acHidden
         
        Reports![repPaymentHistory].Filter = "CustomerId=" & intCustomerID
        
        DoCmd.Close acReport, "repPaymentHistory", acSaveYes
        DoCmd.OutputTo acOutputReport, "repPaymentHistory", acFormatPDF, strPath, False
    "Option1" simple displays the report on the screen giving just one page for the relevant CustomerId.



    However the else branch produces a PDF file with several thousand pages - there are lots of customers!!!

    The Report design has FilterOnLoad = True.
    The only clue I have is that CustomerId is not used in the Report, but in a Query which is the DataSource of the Report (but it works for the "option1" branch????

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,925
    I would just use the filter on the report open as you did with option 1?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    TOPSie is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    108
    Thank you.
    I removed the Reports! and DoCmd.Close line and changed the Open Report line to acHidden and it all now works.

    Does this leave the report hanging around in store? is it best to move the DoCmd Close to the end of the code?

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,925
    Yes close the report after the output.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 08-07-2020, 11:04 AM
  2. Replies: 6
    Last Post: 07-04-2018, 12:54 PM
  3. Replies: 15
    Last Post: 07-14-2014, 11:04 AM
  4. Replies: 2
    Last Post: 04-05-2012, 12:22 PM
  5. Open Report Filter Stopped Working
    By ggs in forum Reports
    Replies: 5
    Last Post: 09-27-2011, 05:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums