Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 05-20-2015, 09:55 AM   #1
jmangual
Newly Registered User
 
Join Date: May 2015
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
jmangual is on a distinguished road
How to attach a PDF-Report to existing Outlook Template

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

jmangual is offline   Reply With Quote
Old 05-21-2015, 12:11 PM   #2
vbaInet
AWF VIP
 
Join Date: Jan 2010
Location: U.K.
Posts: 26,374
Thanks: 0
Thanked 2,418 Times in 2,384 Posts
vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all
Re: How to attach a PDF-Report to existing Outlook Template

Should be:
Code:
    If Not oMsg Is Nothing Then
        oMsg.Attachments.Add "Path:\To\Document", olByValue
        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.
vbaInet is offline   Reply With Quote
The Following User Says Thank You to vbaInet For This Useful Post:
jmangual (05-22-2015)
Old 05-22-2015, 12:12 PM   #3
jmangual
Newly Registered User
 
Join Date: May 2015
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
jmangual is on a distinguished road
Re: How to attach a PDF-Report to existing Outlook Template

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

jmangual is offline   Reply With Quote
Old 05-22-2015, 02:15 PM   #4
vbaInet
AWF VIP
 
Join Date: Jan 2010
Location: U.K.
Posts: 26,374
Thanks: 0
Thanked 2,418 Times in 2,384 Posts
vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all
Re: How to attach a PDF-Report to existing Outlook Template

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.

vbaInet is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SendObject Outlook template Erin Cimbrie Macros 5 11-21-2017 06:49 AM
Send html Outlook Email, options for signature, attach, embed image plus many more nikalopolis Modules & VBA 19 02-16-2016 01:04 AM
Can you attach MS Outlook Email to Records ? ArtW Forms 0 11-23-2011 10:13 AM
Question Can You Attach or Hyperlink a MS Outlook Email to a Record Entry ? ArtW General 0 11-02-2011 12:34 PM
Attach Outlook Messages to form or table razorking General 1 03-01-2011 03:43 PM




All times are GMT -8. The time now is 10:08 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World