How can I attach several reports to one email message?

N

NancyM

I have an Access 2007 database. I would like to press a buttone and have an
email automatically sent containing several reports from the current database
as attachments. The code I am using is:
Private Sub Email_Click()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Nancy Marmat")
' Set the Subject, Body, and Importance of the message.
.Subject = "D4 Multi Panel PO: " & [Forms]![PurchaseOrder]![txtPO]
.Body = "Last test - I promise." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
Set objOutlookAttach = .Attachments.Add([Reports]![PO], olByValue, 1,
"PO")
Set objOutlookAttach = .Attachments.Add([Tables]![PurchaseOrder],
olByValue, 1, "PurchaseOrder")
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
I receive a run-time error 2451
The report "PO" you entered is misspelled or refers to a report that isn't
open or doesn't exist.
The email message is automatically sent if there are no attachments
included, it's only the attachment section that does not work.
Does anyone know how to attach several reports and/or tables from the
current database to one email message?
Any help would be appreciated.
 
T

Tony Toews [MVP]

NancyM said:
Does anyone know how to attach several reports and/or tables from the
current database to one email message?

I have no idea what tables would look like when sent as attachments
and don't really care to experiment to find out. <smile> So I'd
suggest making a report based on that table.

Then I'd suggest explicitly creating PDF files from the reports.

A2000ReportToPDF is an Access 2000 database containing a function to
convert Reports and Snapshot files to PDF documents. No PDF Printer
driver is required. http://www.lebans.com/reporttopdf.htm I use this
solution myself a number of times and am exceedingly happy with it.

Alternatively see Creating PDF files from within Microsoft Access
http://www.granite.ab.ca/access/pdffiles.htm

For a page on how to print a report for a single record and how to
generate reports to attach to emails see the Emailing reports as
attachments from Microsoft Access page at
http://www.granite.ab.ca/access/email/reportsasattachments.htm

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top