I am currently using DoCmd.SendObject to export the current report as a PDF, attach it to an email, and pre-populate the recipient and some of the message body. However, I would like to use the more specific and powerful method for many reasons: I need to ensure that this command will launch through Outlook on other people's computers, and I want to specify body html rather than just body text.
I am not sure how to create the PDF from the report and attach it to the message when using the object method.
Current code that works:
Code:
Private Sub cmdEmail_Click()
On Error GoTo ErrorHandler
Dim email_target As String
email_target = DLookup("email", "tblCustomers", "customerNumber = '" & Reports!rptRFR!cust_nb & "'")
DoCmd.SendObject acReport, "rptRFR", acFormatPDF, email_target, , , "RMA " & Me.[RMA_nb], "Hello," & vbCrLf & vbCrLf &
"Attached is a copy of the RMA that was requested. Please note the RMA instructions on the form. If there are any questions please let
us know.", True
ErrorHandler:
MsgBox ("E-mail was canceled or an error occured - e-mail was not sent!")
End Sub
Outlook Object method that is not yet able to include the PDF:
Code:
'Private Sub cmdEmail_Click()
' Dim appOL As Object
' Dim msgOL As Object
' Dim strSubject As String
' Dim strBody As String
' On Error GoTo ErrHandler
' stSubject = "RMA " & Me![RMA_nb]
' strBody = "Hello," & _
' "<br><br>Attached is a copy of the RMA that was requested. Please note the RMA instructions below, that are also on the attached. If there are any questions please let us know." & _
' "<br><br><b>Instructions:</b>" & _
' "<br><br>Please include a copy of this RMA with the product when being returned. Please ensure that the material is returned within 30 days of the RMA authorization date. If unable to return the product within this 30 day time-frame, please contact Customer Service for an extension. Only one extension will be granted, before the RMA is cancelled. If the material being sent back deviates from the material noted below, please contact Customer Service before sending the material back so that the appropriate updates can be made to ensure timely receipt. (<a href='customerservice@scccombustion.com'>customerservice@scccombustion.com</a>)" & _
' "<br>Guests?:</b>"
' Set appOL = CreateObject(Class:="Outlook.Application")
' Set msgOL = appOL.CreateItem(0)
' With msgOL
' .Subject = strSubject
' .HTMLBody = strBody
' .Display
' End With
' Exit Sub
'ErrHandler:
' MsgBox "E-mail was canceled or an error occured - e-mail was not sent!", vbExclamation
'End Sub