troubleshooting Question

Save Report as PDF and send as attachment through Outlook - Compile Error

Avatar of Lisa Norton
Lisa Norton asked on
Microsoft AccessExchangeOutlook
4 Comments1 Solution90 ViewsLast Modified:
Good Morning,

I would like to use the following code that I found here on Experts Exchange.  I have altered some for my needs.  I get a compile error if I attempt to use this as an On Click Event.  I have also copied and pasted this in a module to use it as a Private Function.  I am not familiar with functions and how to call them or if you can even call them from an on click event.  The compile error occurs at the "DIM appoutlook as new outlook application.  I am using Access 2013.  I appreciate any help with this.  

Private Function SendPDFReport()
'Created by Helen Feddema 17-Jan-2010
'Last modified 17-Jan-2010
On Error GoTo ErrorHandler
   Dim appOutlook As New Outlook.Application
   Dim itm As Outlook.MailItem
   Dim strFileName As String
   Dim rpt As Access.Report
   Dim strReport As String
   Dim strCurrentPath As String
   Dim strFileNameAndPath As String
   strCurrentPath = "C:\users\13618\desktop\pdfs & " \ ""
   strReport = "R_UnitCheckByEmp"
   strFileName = Me.TxtFileName.pdf
   strFileNameAndPath = strCurrentPath & strFileName
   'Output report to PDF in current path
   DoCmd.OutputTo objecttype:=acOutputReport, _
      objectname:=strReport, _
      outputformat:=acFormatPDF, _
      outputfile:=strFileNameAndPath, _
   'Create new mail message and attach text file to it
   Set itm = appOutlook.CreateItem(olMailItem)
   With itm
      .To = ""
      .Subject = "Daily report"
      .Body = "Your message"
      .Attachments.Add strFileNameAndPath
      'To edit before sending
      'To send automatically
   End With
   Exit Sub
   MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
   Resume ErrorHandlerExit
End Function
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros