Full Version: Printing a report to PDF from VBA
UtterAccess Forums > Microsoft® Access > Access Reports
think I need to do a DoCmd.SendTo command to get the report to PDF - is that right?
The report has a screen-only control that I need to create a PDF and then email it. When the button is hit, the report is already on screen and generated, so I need to send the current report rather than get the command to generate the report direct to PDF... I've figured out the email part, but am a bit stuck on the creating PDF... Can someone help with the syntax/code to create the PDF?
If I follow you correctly you only need to add
acFormatPDF to your Docmd.SendObject statement; after the "REport Name" arguement.
Docmd.SendObject acSendReport, "ReportName", acFormatPDF

Hope this helps,
If you need additional help, post your current SendObject statement and I'll update it to send PDF.
Tried that and Access errored out. I call a function to send the email (attaching a file to it) and that works - see the code below.
Public Function CreateEmail( _
    Send_To As String, _
    Subject As String, _
    Message_Body As String, _
    Attachment_Name As String)
Dim olApp As New Outlook.Application
Dim olMail As Outlook.MailItem
Dim olAttachments As Outlook.Attachments
Set olMail = olApp.CreateItem(olMailItem)
Set olAttachments = olMail.Attachments
olAttachments.Add Attachment_Name, olByValue, 1, "Test Description"
With olMail
    .To = Send_To
    .Subject = Subject
    .Body = Message_Body
End With
Set olMail = Nothing
Set olApp = Nothing
End Function

What I need now is the command to push the report that's currently on screen to a PDF (that I can provide the name for) that I can then invoke this function to send the email...
DoCmd.OutputTo acOutputReport, "ReportName", acFormatPDF, "Output Path & Filename"

Oassume you know how to integrate this into your setup?
Let me know if you need more help,
is into my code as: DoCmd.OutputTo acOutputReport, "Quote", acFormatPDF, "Q:\Test.pdf" and Access just errors out with "...cannot find the object '|1' "...
et me clarify just to be on the safe side... this code will sit in the On Click event of a (screen only) control on the report. So when the button is pushed, the report is already on the screen (in report mode) and I just want to PDF that one rather than force the report to run...
Unless something changed in 2010 it should work. It works for me in 2007.
o your report name is "Quote"?
You may need to backup and run a compact & repair on your db.
Maybe even create a blank new DB and import the report and all related tables/queries/forms, etc. into that new db to test
the report outputto pdf code.
Hope you get this worked out,
DOH!!! Finger trouble on my part... it would help if I included the "rpt" prefix the report name... and, you know, it works fine! What a goof-ball - sorry!!
No problem Homey. <
Glad you got it figured out.
Have a great day,
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.