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

    Report to pdf does not filter

    This is driving me mad.
    I have an activity report with the option to print, view on screen or email.
    Both the Print and on screen options correctly filter the report between 2 dates but the pdf produced to be email ignores the filter and has ALL the transactions.


    I have many similar constructs elsewhere which seem to work - so why this defies logic I don't know !!

    Thank you

    Code:
    wHereFilter = "(tblTempCustomerTransactions.Date) Between [Forms]![fdlgCustomerActivityA]![txtDateFrom] And [Forms]![fdlgCustomerActivityA]![txtDateTo]"
    < if printer - just same as screen except acNormal>
    ElseIf [cboPrintDestination] = "Screen" Then    DoCmd.OpenReport "repCustomerActivityHistory", acPreview, , wHereFilter
    
    
      
      Else
        gEmailAddress = wEmail
        gEmailSubject = "xxxxx"
        gEmailMessage = "Please see attached Customer Activity Report"
        strFolder = Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name)))
        strFile = "CustomerActivity.pdf"
        strPath = strFolder & strFile
        DoCmd.OpenReport "repCustomerActivityHistory", acViewDesign, , , acHidden
         Reports![repCustomerActivityHistory].Filter = wHereFilter
        DoCmd.Close acReport, "repCustomerActivityHistory", acSaveYes
        DoCmd.OutputTo acOutputReport, "repCustomerActivityHistory", acFormatPDF, strPath, False

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,010
    Why don't you just open the report with the filter as you do in the first part of the code
    Then output to pdf
    Then Close the report?

    That is how most people handle it.
    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
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,964
    Seems it should work, switching to DesignView and saving is something I have done.

    Open filtered report to preview then code decides what to do with.
    Code:
    DoCmd.OpenReport "repCustomerActivityHistory", acPreview, , wHereFilter, IIf([cboPrintDestination] <> "Screen", acHidden, "")
    If [cboPrintDestination] <> "Screen" Then
        gEmailAddress = wEmail
        gEmailSubject = "xxxxx"
        gEmailMessage = "Please see attached Customer Activity Report"
        strFolder = Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name)))
        strFile = "CustomerActivity.pdf"
        strPath = strFolder & strFile
        DoCmd.OutputTo acOutputReport, "repCustomerActivityHistory", acFormatPDF, strPath, False
        DoCmd.Close acReport, "repCustomerActivityHistory"
    End If
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 7
    Last Post: 12-30-2021, 02:29 PM
  2. Replies: 4
    Last Post: 08-11-2018, 11:22 AM
  3. Replies: 4
    Last Post: 04-30-2014, 09:40 PM
  4. Replies: 1
    Last Post: 07-25-2013, 01:20 PM
  5. Replies: 2
    Last Post: 05-10-2013, 03:37 PM

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