none
Help using vba to send report to pdf

    Question

  • want to put a button on the report menu to send the selected report to a pdf. can anyone help with the code for this?
    Friday, April 08, 2011 7:57 PM

Answers

  • If you need to supply critera or open arg then you need to open the report before sending it to pdf
      DoCmd.OpenReport strReportName, acViewPreview, , strCriteria, acHidden, strArg
      DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, strFullPath
      DoCmd.Close acReport, strReportName
    

    here you see I open the form with criteria and open arg in hidden mode

    then export it to a specified path.


    Kent
    • Marked as answer by ronaldallard Tuesday, April 12, 2011 2:54 PM
    Saturday, April 09, 2011 10:52 PM

All replies

  • DoCmd.SendObject acSendReport,ObjectName,acformatPDF,To,Cc,Bcc,Subject,MessageText,EditMessage,TemplateFile

    See: http://www.fmsinc.com/MicrosoftAccess/Email/SendObject.html

     

    Friday, April 08, 2011 8:38 PM
  • http://msdn.microsoft.com/en-us/library/bb238050(v=office.12).aspx

    DoCmd.OutputTo acOutputTable, "<table name>", acFormatPDF, "<file path/name>.pdf"

    "You can save as a PDF or XPS file from a 2007 Microsoft Office system program only after you install an add-in. For more information, search for "Enable support for other file formats, such as PDF and XPS" on Office Online"

    Saturday, April 09, 2011 7:40 PM
  • If you need to supply critera or open arg then you need to open the report before sending it to pdf
      DoCmd.OpenReport strReportName, acViewPreview, , strCriteria, acHidden, strArg
      DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, strFullPath
      DoCmd.Close acReport, strReportName
    

    here you see I open the form with criteria and open arg in hidden mode

    then export it to a specified path.


    Kent
    • Marked as answer by ronaldallard Tuesday, April 12, 2011 2:54 PM
    Saturday, April 09, 2011 10:52 PM
  • I did it this way because I have to pull the report for an employee specified. However, when it does the output the report is no longer filtered??? I tried opening the form normal mode just to see if the filter was working and it was. But when I open the output PDF it has everyone in there? Help???  Here is my code:

            strCriteria = "NameKey = '" & Me!lst_Employee.ItemData(i) _
            & "' and [WorkType] = '" & Left(Me!lst_Employee.Column(3, i), 1) & "'"


            ' Send the report(s) selected to a PDF file.
            DoCmd.OpenReport "rpt_WAD", acViewNormal, , strCriteria, acHidden
                DoCmd.OutputTo acOutputReport, "rpt_WAD", acFormatPDF, FilePath
            DoCmd.Close acReport, "rpt_WAD"

    Monday, April 11, 2011 6:38 PM
  • I've used bullzip pdf printer.

    see this

    http://www.biopdf.com/guide/examples/microsoft_access/

     

    Monday, April 11, 2011 6:44 PM
  • Ronald,

    Your code looks right and should work, I do this a lot.

    Try opening the report without the acHidden

    run the output as you are doing

    don't close the report, leave it open so you can see it to compare the outputs.

    now with the report still open, open the pdf and compare.

    What is the result?

     


    Kent
    Monday, April 11, 2011 9:08 PM
  • The problem hit me like a ton of bricks! I have acViewNormal... Report was gone by the time the output happened. changed it to acViewPreview and it is working great... Thanks!!!
    Tuesday, April 12, 2011 2:56 PM
  • Hey, man, GREAT help.  Thank YOU!!!
    Thursday, May 05, 2011 5:36 AM