Full Version: Printing a report to PDF from VBA
UtterAccess Discussion Forums > Microsoft® Access > Access Reports
Taz2
Hi

I 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?

Thanks
AC2Designs
If I follow you correctly you only need to add
acFormatPDF to your Docmd.SendObject statement; after the "REport Name" arguement.

CODE
Docmd.SendObject acSendReport, "ReportName", acFormatPDF


etc.

Hope this helps,

If you need additional help, post your current SendObject statement and I'll update it to send PDF.

Kevin

Taz2
QUOTE (AC2Designs @ Sep 15 2010, 12:47 PM) *
If I follow you correctly you only need to add
acFormatPDF to your Docmd.SendObject statement; after the "REport Name" arguement.

CODE
Docmd.SendObject acSendReport, "ReportName", acFormatPDF


etc.

Hope this helps,

If you need additional help, post your current SendObject statement and I'll update it to send PDF.

Kevin
Hi Kevin

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.
CODE
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
    .Display
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...
AC2Designs
Try:

CODE
DoCmd.OutputTo acOutputReport, "ReportName", acFormatPDF, "Output Path & Filename"


I assume you know how to integrate this into your setup?

Let me know if you need more help,

Kevin
Taz2
QUOTE (AC2Designs @ Sep 15 2010, 02:47 PM) *
Try:

CODE
DoCmd.OutputTo acOutputReport, "ReportName", acFormatPDF, "Output Path & Filename"


I assume you know how to integrate this into your setup?

Let me know if you need more help,

Kevin
put this into my code as: DoCmd.OutputTo acOutputReport, "Quote", acFormatPDF, "Q:\Test.pdf" and Access just errors out with "...cannot find the object '|1' "...

Let 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...

Thanks
AC2Designs
Unless something changed in 2010 it should work. It works for me in 2007.

So 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,

Kevin
Taz2
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!!
AC2Designs
No problem Homey. smile.gif
Glad you got it figured out.

Have a great day,

Kevin
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.