Results 1 to 7 of 7

Module to Print Reports

  1. #1
    shank is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    119

    Module to Print Reports

    I have the below code that actually works and prints the reports, just not in my chosen folder.



    Data...
    ReportName: Invoice Summary
    FolderPath: S:\Order Imports\Electronics\Reports\
    FileNam: Invoice Summary 646969 101319-101919.pdf


    I'm expecting the PDF to land in:
    S:\Order Imports\Electronics\Reports\Invoice Summary 646969 101319-101919.pdf


    However, it's landing in the same folder as my database:
    S:\Databases\Invoice Summary 646969 101319-101919.pdf

    Is there something obvious I'm doing wrong?

    How can I print to the intermediate window so I can see what's happening?

    Code:
    Public Function PrintReports()
    
    
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim varQuery As String
        Dim varReportName As String
        Dim varFolderPath As String
        Dim varFileNam As String
        
        varQuery = "qry_Reports_Print"
        
        Set db = CurrentDb()
    
    
        Set rs = db.OpenRecordset("SELECT ReportName, FolderPath, FileNam FROM " & varQuery, dbOpenSnapshot)
    
    
        Do While Not rs.EOF
        
        varReportName = rs("ReportName")
        varFolderPath = rs("FolderPath")
        varFileNam = rs("FileNam")
    
    
            'acViewPreview = Print Preview, acViewReport = Direct to Printer
            DoCmd.OpenReport varReportName, acViewPreview, , "'" & varFolderPath & "'"
            DoCmd.OutputTo acOutputReport, "", acFormatPDF, varFileNam
            DoCmd.Close acReport, varReportName
            DoEvents
    
    
            rs.MoveNext
        Loop
    
    
    
    
        rs.Close
        Set rs = Nothing
        Set db = Nothing
    
    
    End Function
    thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    20,617
    Perhaps

    DoCmd.OutputTo acOutputReport, "", acFormatPDF, varFolderPath & varFileNam

    presuming the first includes the trailing \.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    shank is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    119
    Yes, the folder path from the query includes trailing ""
    FolderPath: S:\Order Imports\Electronics\Reports\

    Is there a way to print to the intermediate window so I can see what's actually happening as the code runs?
    Or perhaps to a log somewhere?

    Thanks!

  4. #4
    shank is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    119
    I figured out how to Debug.Print my variables. See below results.

    What I don't know is whether my syntax is correct. Do any of the below variables need to have quotes around them because there's spaces in the intended full path?
    S:\Order Imports\Electronics\Reports\Invoice Summary 646969 101319-101919.pdf

    Debug.Print varReportName
    Debug.Print varFolderPath
    Debug.Print varFileNam


    Invoice Summary
    S:\Order Imports\Electronics\Reports\
    Invoice Summary 646969 101319-101919.pdf


    Sold Qty
    S:\Order Imports\Electronics\Reports\
    Sold Qty 646969 101319-101919.pdf


    Available Qty
    S:\Order Imports\Electronics\Reports\
    Available Qty 646969 101319-101919.pdf


    Returns
    S:\Order Imports\Electronics\Reports\
    Returns 646969 101319-101919.pdf


    PA Invoice Reports
    S:\Order Imports\Electronics\Reports\
    PA Invoice Reports 646969 101319-101919.pdf


    Invoice Breakout
    S:\Order Imports\Electronics\Reports\
    Invoice Breakout 646969 101319-101919.pdf

  5. #5
    accesstos's Avatar
    accesstos is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    275
    Errors:
    1. You pass the value 'S:\Order Imports\Electronics\Reports\' to the WhereCondition argument (!).

    2. You pass only the file name as OutputFile in OutputTo command.

    Suggestion:
    Code:
    Do While Not rs.EOF
         Debug.Print "Output report: " & rs("ReportName") & " to path: " rs("FolderPath") & " as: " & rs("FileNam")
         DoCmd.OutputTo acOutputReport, rs("ReportName"), acFormatPDF, rs("FolderPath") & rs("FileNam")
    Loop
    No need extra variables, or open/close reports.

  6. #6
    shank is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    119
    That worked great! Slowly but surely I'm learning.

    Thank you very much!

  7. #7
    accesstos's Avatar
    accesstos is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    275
    You are welcome!

    Learning is a major pleasure of life. Offering is an other also too.

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

Similar Threads

  1. RunCode - Module to print PDF
    By shank in forum Modules
    Replies: 4
    Last Post: 05-15-2019, 04:30 PM
  2. Replies: 2
    Last Post: 03-30-2017, 03:14 PM
  3. Replies: 2
    Last Post: 02-15-2015, 11:36 AM
  4. Reports only print once
    By Perceptus in forum Reports
    Replies: 3
    Last Post: 10-02-2014, 10:10 AM
  5. Reports print Twice
    By brharrii in forum Reports
    Replies: 5
    Last Post: 10-31-2012, 02:22 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
  •  
Tech Forums: Microsoft Office Forums