Question : MS Access 2003 Report - create as pdf then email as attachment via Outlook 2003

When running the below code, it successfully creates a pdf file from the report, but I receive the following error when it attempts to attach the pdf file as an Outlook attachment:

"Can't find the file.  Make sure the path and file name are correct".  

 Why can't it locate the file?  The pdf file  is there.  I copied and pasted the path and file name from Windows 2000 Explorer to make certain it was correct.

Option Explicit

Public Function EmailPDFRpt()
'To create a PDF file from a MS Access report
'Uses Adobe Acrobat Professional 8
'Adobe PDF printer is assigned as default printer

Dim prnt As Printer
Dim strRptName As String
Dim strPDFPathNameMe As String
Dim objOutlookApp As Object
Dim objMailItem  As Object

Set prnt = Application.Printers(0) 'Adobe pdf Printer (the default printer)
Set objOutlookApp = CreateObject("Outlook.Application") '(Set up Outlook as an object)
Set objMailItem = objOutlookApp.CreateItem(0) '(An Outlook Mail Message)
strRptName = "rPDF-Email-Test" 'The MS Access Report's name
'The path and name of PDF file:
strPDFPathNameMe = "\\servername\users$\my.name\My Documents\PDF Files\rPDF-Email-Test.pdf"


'Closes the MS Access opening form "fOpenForm" so Adobe will not print it
DoCmd.Close acForm, "fOpenForm", acSaveNo
'Open and send report to Adobe PDF printer (the default priner)
DoCmd.OpenReport strRptName, acViewNormal, "", "", acHidden
DoCmd.Close acReport, strRptName

'Adobe will automatically give the pdf file the MS Access report name
'Email the pdf file via Outlook
     Dim ol As Object
     Dim itm  As Object '(Creates the Outlook Application Object by accessing the MS Outlook COM Type Library)
     Set ol = CreateObject("Outlook.Application")
     Set itm = ol.CreateItem(0) '(Outlook a Mail Message)
     itm.To = "[email protected]"
     itm.Subject = "Auto Reports - PDF ADM AUTO RPT"
     itm.Body = "Attached IS A PDF FILE"
     itm.Attachments.Add ""\\servername\users$\my.name\My Documents\PDF Files\rPDF-Email-Test.pdf""
     itm.Send  '(to send)
     Set itm = Nothing '(Cleans up)
     Set ol = Nothing
   
End Function

Answer : MS Access 2003 Report - create as pdf then email as attachment via Outlook 2003

Thank you for replying pwtucker.  I did try changing the path  to include the opening and closing parentheses, but it did not help.

What I finally found that did work was adding an "On Error GoTo" statement:
  On Error GoTo Err_EmailPDFRpt

Then in the "Err_EmailPDFRpt:" statement
   Resume Next

Even though an error message box popped up stating it could not find the pdf file, the pdf file was being created and it was there.  So by adding an error message "trap", the code bypassed the error message, continued and sent the pdf file.

You were the only one that replied, and I appreciate your input.  I will award you points.  Thanks again.
Random Solutions  
 
programming4us programming4us