How to attach a PDF-Report to existing Outlook Template (1 Viewer)

jmangual

New member
Local time
Yesterday, 18:01
Joined
May 20, 2015
Messages
3
Hello!

Am working in MS Access 2013 and I have a form with a button, I need the button to doattach automatically the pdf-report to the email template(i don't want to attach the pdf to a new email)

Right now the command open the E-mail template and create the pdf-report in the desktop

All suggestions are welcome

Code:
Private Sub Command18_Click()
    
    Dim oApp As Outlook.Application
    Dim oMsg As Outlook.MailItem
    Dim oAttachment As Outlook.attachment
    
 
    Set oApp = New Outlook.Application
    Set oMsg = oApp.CreateItemFromTemplate("*\\filepath*\comienzo_campana.oft")
    DoCmd.OutputTo acOutputReport, "email-campanas-lista", acFormatPDF
    
    If Not oMsg Is Nothing Then
        oMsg.Display
        Set oMsg = Nothing
    Else
        MsgBox "Template Not Found. Contact I.T team"
    End If
End Sub
 

vbaInet

AWF VIP
Local time
Today, 02:01
Joined
Jan 22, 2010
Messages
26,374
Should be:
Code:
    If Not oMsg Is Nothing Then
        [COLOR="Blue"]oMsg.Attachments.Add "Path:\To\Document", olByValue[/COLOR]
        oMsg.Display
    Else
NB: If your report takes a little long to run, you might want to ensure that it completes outputting the file before attempting to attach it.
 

jmangual

New member
Local time
Yesterday, 18:01
Joined
May 20, 2015
Messages
3
Thx for the help!

Got it!

Code:
Dim oApp As Outlook.Application
Dim oMsg As Outlook.MailItem
Dim oAttachment As Outlook.attachment
Dim strPath As String
   
   strPath = "C:"""\reportdoc.PDF"
   Set oApp = New Outlook.Application

   ''Get template for email
   Set oMsg = oApp.CreateItemFromTemplate("\C:"""\email_template.oft")

'' create report in PDF format and save it
   DoCmd.OutputTo acOutputReport, "reportdoc", acFormatPDF, strPath, True
    
   
   With oMsg
''attach report to email
   .Attachments.Add "C:"""\reportdoc.PDF"

    End With
   If Not oMsg Is Nothing Then
        oMsg.Display
        Set oMsg = Nothing
    Else
       MsgBox "Template Not Found. Contact I.T team"
    End If
End Sub
 

vbaInet

AWF VIP
Local time
Today, 02:01
Joined
Jan 22, 2010
Messages
26,374
Good, but you've put the code in the wrong place. Please look at my post again for the exact location where it should go.
 

Users who are viewing this thread

Top Bottom