Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I attach both an Access report and an external PDF to the same email generated within Access

Status
Not open for further replies.

MacroScope

Programmer
Jul 17, 2010
286
0
0
US


I am trying to attach an internal Access report and an external .pdf file to an email generated within Access. I've read up on the limitations of the SendObject command and it apparently only allows one attachment.

The flip side is to send as an Outlook application, and while it allows multiple attachments they seem to be only external documents located somewhere on one of the drives.

Is it possible to do both? I'm using Access 2007 with SQL Server 2012.

All assistance will be appreciated.
 
I have code that will save the access report as a pdf and then attach it to an email. Since it uses automation of outlook you should be able to code it to then attach the second pdf as well. Would that suffice?
 
That would be quite helpful, and I'd appreciate it if you'd send it.

I'm a bit confused because I did get this working myself, and I posted a response here telling others that I had done so, but for some reason the response didn't show up. It's my fault that I really didn't bother to check to confirm.

The method I chose was to use Outlook's multiple attachment features. I used the OutputTo action within Access to output the report as a .pdf file to my C:\ Drive and then I was able to attach the report and the external document to the email together.

I feel really badly that my response didn't show up in the forum. I really appreciate all the selfless work and effort that posters put in here, and I had hoped to let people know that I had it under control. With that said, I'm always looking for alternate ways of doing things and I'd be very interested in whatever information you can send.
 
Did you get the info? If not, the following code assumes that you have at lease access 2007 or later.

Code:


There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.

 
The code didn't post, so here it is

Function SendMyPDFs()
Dim objOutlook As Object 'Outlook.Application
Dim ItmNewEmail As Object 'Outlook.MailItem
Dim OutputFileName As String
Dim RptName As String
Dim FN As String

RptName = "MyReport" ' The report you want to make into a PDF
FN = "C:\MyReports\MyReport.PDF" ' Where to export your report

Set objOutlook = CreateObject("Outlook.Application")
Set ItmNewEmail = objOutlook.CreateItem(olMailItem)

DoCmd.OutputTo acOutputReport, RptName, acFormatPDF, OutputPDFname, False

With ItmNewEmail
.To = ""
.CC = ""
.Subject = sArgs
.Body = "My Report"
.Attachments.Add FN ' The repoort you just exported
.Attachments.Add "C:\MyReports\My other PDF.PDF" ' The other PDF you want to attach
.Display
End With
End Function


There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.

 
Thank you very much. It is quite similar to the code I wound up using.

As this code does, I wound up using the OutputTo command to turn the report into a .pdf at a known location on the hard drive, and then I attached the report and the other document that I was trying to add using Outlook rather than SendObject commands, as you have done here.

I actually think your code is a bit cleaner than mine, but at this point it's working well and I probably won't revisit it just to make it prettier.

I honestly appreciate all of the efforts that everyone here puts forth to help others. It takes a special kind of person do do this at the going pay rate!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top