Results 1 to 6 of 6
  1. #1
    ahoneycutt is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    18

    Creating PDF's with multiple pages based on a specific field in a query

    I am using some code I found online that runs a report and saves the reports to a PDF. The code works with no errors but it is producing only one page per pdf when it should be multiple pages.

    My data has 25 records in it. The field DirectReportsTo consist of 5 unique people and each of those has on average 5 people associated with them. If I run the report on it's own it prints in order by the 5 unique people and prints all pages. When I run the code I get a PDF for each of the 5 people as I desire but within those PDF's I want to see multiple pages yet I only see 1 page per pdf.

    Example.

    DirectReports Psoft_ID
    John Smith 123442
    John Smith 125478
    John Smith 125477
    Jim Scott 458745
    Jim Scott 458999
    Jim Scott 788956

    I want to see one pdf for John Smith and in it is a report for his 3 people and one pdf for Jim Scott and his 3 people in it. The code below gives me one pdf for John Smith with only one person in it and one pdf for Jim Scott with one person in it.

    The report is grouped by DirectReportTo and is sorted in PSoft_ID order. I have tried everything I can to change the code with no luck. I'm a novice with vba so appreciate any help.

    Dim rst As DAO.Recordset
    Dim db As DAO.Database
    Dim strSQL As String
    Dim strPath As String

    Set db = CurrentDb()

    Set rst = db.OpenRecordset("Select DISTINCT Psoft_ID, DirectReportsTo from [qryRPT_1PGR_distribution_EVPs]", dbOpenDynaset)

    rst.MoveFirst

    Do Until rst.EOF
    DoCmd.OpenReport "rpt1PAGER_Final_BonusOnly_Distribution", acViewPreview, , "Psoft_ID= " & rst!PSoft_ID
    strPath = "C:\PDFs\1Pgrs" & rst!DirectReportsTo & ""
    Call MakeSureDirectoryPathExists(strPath)


    DoCmd.OutputTo acOutputReport, "rpt1PAGER_Final_BonusOnly_Distribution", acFormatPDF, strPath & rst!DirectReportsTo & ".pdf", False
    DoCmd.Close acReport, "rpt1PAGER_Final_BonusOnly_Distribution"
    rst.MoveNext
    Loop

    rst.Close
    Set rst = Nothing
    strSQL = ""

    End Sub

    Would be a great Mother's Day gift to be able to get this code working so at work tomorrow I will be able to have this task complete.

    Thanks in advance for your help.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Just a guess, but should the report be filtered with DirectReportsTo instead of PSoft_ID?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ahoneycutt is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    18
    I changed it to DoCmd.OpenReport "rpt1PAGER_Final_BonusOnly_Distribution", acViewPreview, , "[DirectReportsTo]='" & rst!DirectReportsTo & "'" but I still only get one page per person.

    Am I doing something wrong?

    Thanks in advance.

  4. #4
    ahoneycutt is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    18
    I don't understand why but after changing how the where clause was written it worked. I was not getting an error before but obviously it didn't like it.

    Here is the new code. It works great.

    Dim rst As DAO.Recordset
    Dim db As DAO.Database
    Dim strSQL As String
    Dim strPath As String

    Set db = CurrentDb()

    Set rst = db.OpenRecordset("Select DISTINCT Psoft_ID, DirectReportsTo from [qryRPT_1PGR_distribution_EVPs]", dbOpenDynaset)

    rst.MoveFirst

    Do Until rst.EOF
    DoCmd.OpenReport "rpt1PAGER_Final_BonusOnly_Distribution", acViewPreview, , "[DirectReportsTo]='" & rst!DirectReportsTo & "'"
    strPath = "C:\PDFs\1Pgrs" & rst!DirectReportsTo & ""
    Call MakeSureDirectoryPathExists(strPath)
    DoCmd.OutputTo acOutputReport, "rpt1PAGER_Final_BonusOnly_Distribution", acFormatPDF, strPath & rst!DirectReportsTo & ".pdf", False
    DoCmd.Close acReport, "rpt1PAGER_Final_BonusOnly_Distribution"
    rst.MoveNext
    Loop

    rst.Close
    Set rst = Nothing
    strSQL = ""

    End Sub

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Glad you got it working.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    DavidMcArthur is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jun 2016
    Posts
    18
    Thanks for this, looks like its something i could adapt my database with!

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

Similar Threads

  1. Replies: 2
    Last Post: 08-13-2014, 09:38 AM
  2. Replies: 1
    Last Post: 07-17-2013, 02:02 PM
  3. Creating groups based on multiple values
    By cardgage in forum Queries
    Replies: 2
    Last Post: 03-28-2013, 08:29 AM
  4. Creating Web Pages
    By prstoessel in forum Access
    Replies: 7
    Last Post: 08-06-2011, 11:28 AM
  5. Replies: 1
    Last Post: 11-10-2009, 03:20 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