Results 1 to 6 of 6
  1. #1
    kid is offline Novice
    Windows 10 Access 2007
    Join Date
    Jan 2020
    Posts
    20

    Export report to multiple pdf based on group

    I want export my report to multiple pdf with the name of the (GROUP BY) field .

    For example My query is
    Code:
    "SELECT EMPLOYEE,AGE FROM MASTER GROUP BY TEAM
    This is my query to report.I used group based on TEAMS field .Now I want a macro to export report to pdf .

    such as BLUE.pdf,GREEN.pdf..... (BLUE,GREEN... are TEAM names)

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Open a recordset object, loop through records, open report filtered by value from recordset, OutputTo pdf, close report, move to next record, repeat. This is a fairly common topic and code examples are available. See suggested threads for review at bottom of this page.
    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.

  3. #3
    kid is offline Novice
    Windows 10 Access 2007
    Join Date
    Jan 2020
    Posts
    20
    Code:
    Sub test()
    
    
       Dim rsContracts As DAO.Recordset
         Dim ColumnName As String
    Set rsContracts = CurrentDb.OpenRecordset( _
        "SELECT DISTINCT TEAMS FROM MASTER ")
       Do Until rsContracts.EOF
        ColumnName = rsContracts!TEAMS
        DoCmd.OpenReport "MAS_REPORT", acViewPreview, , "TEAMS= '& ColumnName &'"
        DoCmd.OutputTo acOutputReport, "MAS_REPORT", acFormatPDF, "c:\test\" & ColumnName & ".pdf"
           rsContracts.MoveNext
      Loop
    
    
       End Sub
    I tried this above code. I got renamed pdfs But it prints all pages.

    My report Query is

    Code:
    SELECT * FROM MASTER

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Code works for me.

    Your OpenReport filter criteria syntax is wrong. Missing quote marks.

    DoCmd.OpenReport "MAS_REPORT", acViewPreview, , "TEAMS= '" & ColumnName & "'"
    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.

  5. #5
    kid is offline Novice
    Windows 10 Access 2007
    Join Date
    Jan 2020
    Posts
    20
    ..
    But the important thing here is I do not close the form too.(before the loop close)

    Code:
     DoCmd.Close acReport, "MAS_REPORT"

    Now , It works fine...

    Thank you.. June7


  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Ooops, yes. I should have noticed that. I was testing filtered to single record. Glad you got it working.
    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: 3
    Last Post: 07-26-2016, 02:12 PM
  2. Replies: 6
    Last Post: 10-22-2015, 06:12 AM
  3. Replies: 8
    Last Post: 06-24-2015, 08:22 AM
  4. Export multiple records based on a field
    By dskulman in forum Import/Export Data
    Replies: 0
    Last Post: 03-03-2011, 02:44 PM
  5. export to multiple sheets based on change in sort
    By mws5872 in forum Programming
    Replies: 0
    Last Post: 06-30-2009, 07:55 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