Link to home
Start Free TrialLog in
Avatar of dminx13
dminx13Flag for United States of America

asked on

Code not attaching .pdf file

I have a process that creates a .pdf file, attaches it to email and sends.

For some reason it isn't attaching the pdf to the email.

We've had this problem years and years ago and can't find the fix on it. I THINK it is a setting in adobe but am not sure. Anyone know anything about this?

Thanks
Deanna
Avatar of PatHartman
PatHartman
Flag of United States of America image

Is it never attaching the pdf or is the behavior intermittent?   Please post the code you are using.
Avatar of dminx13

ASKER

Oh.... I was hoping for adobe settings to try...... :-( let me see if I can find it............ Sorry, this upgrade has been nightmare after nightmare and I'm getting tired of things not working. I appreciate the help will post code today if I can get to it. Working on anohter broken piece of code as well. Already fixed 2 today and there are many more that are still broken. :-(
Are you using the built-in Export to PDF feature in Access 2007 and higher?  Here is some standard code I use for this purpose:

Public Sub ExportReportToPDF()
'Created by Helen Feddema 12-Jul-2013
'Last modified by Helen Feddema 12-Jul-2013

On Error GoTo ErrorHandler

   Dim appOutlook As New Outlook.Application
   Dim strReport As String
   Dim strSavePath As String
   Dim strReportFile As String
   Dim itm As Outlook.MailItem
   Dim strEmail As String
   
   strReport = "rptCurrentData"
   strSavePath = "G:\Documents\PDFs\"
   strEmail = "user@email.com"
   strReportFile = strSavePath & "Current Data.pdf"
   
   'Create PDF file
   DoCmd.OutputTo objecttype:=acOutputReport, _
      objectname:=strReport, _
      outputformat:=acFormatPDF, _
      outputfile:=strReportFile, _
      autostart:=True
   
   'Create email
   strEmail = "Email address"
   Set itm = appOutlook.CreateItem(olMailItem)
   itm.Subject = "Message Subject"
   itm.Body = "Message body"
   itm.To = strEmail
   itm.Attachments.Add Source:=strReportFile, _
      Type:=olByValue
   itm.Display
   
ErrorHandlerExit:
   Set appOutlook = Nothing
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number & "; Description: "
   Resume ErrorHandlerExit

End Sub

Open in new window


**email removed 12-6-13 MIT ****
Avatar of dminx13

ASKER

Here is the code. We don't use outlook. We have groupwise

Private Sub ProcessManagerEmail(ManagerID As String, UserName As String, _
                                FirstName As String, LastName As String, _
                                TableName As String, PPEndDate As Date)
    '  Procedure is used to create the pdf file
    '  create email with pdf attachment
    '  send the email
    Dim strRptSQL As String
    Dim strFile As String
    Dim lng As Long
    Dim strHeader As String
    Dim strMsg As String
    Dim strAddress As String
    Dim fCEO As Boolean
    
    
    '  Is this the CEO Email?
    If ReportTo(ManagerID, True) = "9~999999" Then
        '  This is the CEO
        fCEO = True
    Else
        fCEO = False
    End If
    
    Debug.Print FirstName + " " + LastName
    
    '  Create the report SQL Statement
    strRptSQL = ReportSQL(ManagerID, TableName, PPEndDate)
    
    '  Does the recordset have any data
    If ReviewReportHasData(strRptSQL) = True Then
        '  Determine the FileName
        strFile = "c:\temp\Reviews Due.pdf"
        '  Set the file name
        lng = SetPDFName(strFile)
        
        '  Create the pdf file
        Call OpenReport("CompReviewDue", strRptSQL, True)
        
        '  Prepare the email
        strHeader = "Staff Reviews Due"
        
        
        strMsg = ""
        '  Message
        '  New Part
        strHeader = "Staff Reviews Due"
        
        strMsg = strMsg + "The attached report is a "
        strMsg = strMsg + "consolidated, current list of performance reviews "
        strMsg = strMsg + "due for staff members that report to you. "
        strMsg = strMsg + "This information is "
        strMsg = strMsg + "based on what we have "
        strMsg = strMsg + "received in Human Resources as of "
        strMsg = strMsg + CStr(Format(DateAdd("d", -5, Date), "mmmm d, yyyy"))
        strMsg = strMsg + "."
        strMsg = strMsg + vbCrLf + vbCrLf
        'reinstate when we have merits again
        'strMsg = strMsg + "Please be aware that merit increases may not be reflected "
        'strMsg = strMsg + "until the following pay period due to our payroll processes."
        'strMsg = strMsg + " If you have any questions regarding your reviews or merit "
        'comment out following line once merits are back
        strMsg = strMsg + " If you have any questions regarding your reviews, "
        strMsg = strMsg + "please contact me at "
        strMsg = strMsg + "extension xxxx."
        strMsg = strMsg + vbCrLf + vbCrLf
        strMsg = strMsg + "Reviews completed more than 60 days "
        strMsg = strMsg + "after the due date will be considered out of compliance with policy."
        strMsg = strMsg + vbCrLf + vbCrLf
        'strMsg = strMsg + "Please remember for FY07 our merit budget is 3% and we have "
        'strMsg = strMsg + "new merit opportunities (2%, 2.5%, 3%, 3.5%, 4%)."
        'strMsg = strMsg + vbCrLf + vbCrLf
        strMsg = strMsg + "We appreciate your help to "
        strMsg = strMsg + "ensure these reviews are "
        strMsg = strMsg + "completed in a timely "
        strMsg = strMsg + "manner."
        strMsg = strMsg + vbCrLf + vbCrLf
        strMsg = strMsg + "Thank You."
        'strMsg = strMsg + vbCrLf
        'strMsg = strMsg + "ThePersonWhoSentThis"
        
        '  If this is a test - add the manager name to the header
        If Me.frmTest = 2 Then
            strHeader = "Review Test: " + LastName + ", " + FirstName
            
        End If
        
        
        '  Will this do to the manager or for testing
        If Me.frmTest = 1 Then
            '  manager
            If fCEO = True And Me.chkSendToUser = False Then
                '  Send CEO to the CEO
                strAddress = UserName + "@companyemail.com"
            ElseIf fCEO = True And Me.chkSendToUser = True Then
                '  Send the CEO message to the user - serves as an all report
                strAddress = GetSystemData("CurrentUser") + "@companyemail.com"
            Else
                '  non CEO message - send to the manager
                strAddress = UserName + "@companyemail.com"
            End If
        Else
            '  user - TESTING - send all to the user
            strAddress = GetSystemData("CurrentUser") + "@companyemail.com"
        End If
    
        '  Attach and send to the manager in an E-Mail
        Call SendEmail(strAddress, strHeader, strMsg, False, , , CVar(strFile))
        'Call SendEmail("user@companyemail.com", strHeader, strMsg, False, , , CVar(strFile))
        
        '  delete the file
        On Error Resume Next
        Kill strFile
    End If
    
End Sub

Open in new window


***Email edited MIT 12-6-13***
Avatar of dminx13

ASKER

This is sending the emails. And even the first email is getting the attachment. It is just the emails after the first: No attachment.

What is supposed to happen is report is generated, saved in a temp file, attached to email, sent, report is generated, overwrites existing, attaches to email, sent, etc through all the managers.
Avatar of dminx13

ASKER

I've requested that this question be deleted for the following reason:

entered info in post I should not have. please delete asap
Avatar of dminx13

ASKER

Thank you!!!!!!
I am not familiar with Groupwise, but if the PDF is attached to the first message only, this might be a problem with overwriting.  You might need to delete the old file before writing another file of the same name.  This can sometimes be a problem on Drive C: with Windows 7 or higher.
ASKER CERTIFIED SOLUTION
Avatar of dminx13
dminx13
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dminx13

ASKER

Figured this out on my own after some code searching. Check naming conventions on what the file is being saved as against when the email attachment is looking for.