I want to send an e-mail with a report as attachment.
On the internet i have found two options, and both are not the best solutions.
1. option
With this construction I don't have enough control over the mail, and worse, I get an Outlook message when the mail is sending which I have to answer.
2. option
with this construction I have to enter an existing report.pdf on my filesystem (bold line), but I want to pass the rpt object straight to the mail as an attachment. How can I build this?
On the internet i have found two options, and both are not the best solutions.
1. option
Code:
DoCmd.SendObject acSendReport, sReport, acFormatPDF, sMailAdres
With this construction I don't have enough control over the mail, and worse, I get an Outlook message when the mail is sending which I have to answer.
2. option
Code:
Dim oMail As MailItem
Dim oAtt As Attachment
Set oApp = CreateObject("Outlook.application")
Set oMail = oApp.CreateItem(olMailItem)
DoCmd.OpenReport ReportName:=sReport, View:=acViewPreview, WindowMode:=acHidden
Set rpt = Reports(sReport)
oMail.Body = "Body of the email"
oMail.Subject = "Test Subject"
oMail.To = "107mb@mail.nl"
[B]oMail.Attachments.add rpt[/B]
oMail.Send
with this construction I have to enter an existing report.pdf on my filesystem (bold line), but I want to pass the rpt object straight to the mail as an attachment. How can I build this?