Converting report to PDF and attach it to email

crxftw

Registered User.
Local time
Today, 14:59
Joined
Jun 9, 2011
Messages
81
Hello, I've been trying to find solutions how I am able to convert currently opened report to PDF and attach it to outlook e-mail. I am using Access2k10 and I tried EmailDatabaseObject macro function and SendObject through VBA but these have some flaws that I can't have. I need message body to be either from template file (message text is different which depends on area to where email will be sent). Both that I mentioned don't let me format body text in html which i need as I must get logo to email together with long text.

Any suggestions how it's the easiest way to do these two (convert to pdf and attach to outlook) operations with one button click?

Regards
 
You could use the Docmd.outputTo command to create the pdf giving a folder and name, then use the Outlook object to create your email and attach the pdf.

HTH
 
That's actually what I am trying to do right now, but how it's the best way to make it pick which message text I wanna use? Simple If statement for both letters would work, but maybe it's wise to store templates into tables and get them to vba through query?

And I seem to have problem with selecting directory where OutputTo is gonna save the pdf (and I think I'd like this pdf to get deleted so it's only temporary after it's attached to the email?) Right now I am trying to select the current directory where the db is itself via
Code:
mydir = Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name)))
for converting
Code:
DoCmd.OutputTo acOutputReport, [Report].[Name], acFormatPDF, mydir & [txtInvoiceNumber] & ".pdf", False, , , acExportQualityScreen
and to attach it
Code:
.Attachments.Add (mydir & [txtInvoiceNumber] & ".pdf")
Not sure if I am doing it right, yesterday it somehow worked but today getting errors like "Unable to save it to this location" etc

Regards
 
Last edited:

Users who are viewing this thread

Back
Top Bottom