Solved

Code not attaching .pdf file

Posted on 2013-12-05
11
576 Views
Last Modified: 2013-12-15
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
0
Comment
Question by:dminx13
  • 7
  • 2
11 Comments
 
LVL 34

Expert Comment

by:PatHartman
ID: 39699330
Is it never attaching the pdf or is the behavior intermittent?   Please post the code you are using.
0
 

Author Comment

by:dminx13
ID: 39699734
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. :-(
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 39701500
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 ****
0
 

Author Comment

by:dminx13
ID: 39701746
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***
0
 

Author Comment

by:dminx13
ID: 39701767
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.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:dminx13
ID: 39701850
I've requested that this question be deleted for the following reason:

entered info in post I should not have. please delete asap
0
 

Author Comment

by:dminx13
ID: 39701862
Thank you!!!!!!
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 39702428
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.
0
 

Accepted Solution

by:
dminx13 earned 0 total points
ID: 39709276
I figured this one out. The code was looking for one .pdf name and another code was saving it with the incorrect name. So when the email was looking for reviews.pdf it could not find it because it was compreviews.pdf......
0
 

Author Closing Comment

by:dminx13
ID: 39719743
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.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article is in response to a question here (http://www.experts-exchange.com/Other/URLs/Q_28283850.html) at Experts Exchange. The Original Poster has a scanned signature and wants to make the background transparent so that the signature may be pl…
*Adobe Acrobat 9 was used for this article. Particular steps may vary depending on software versions. 1. Create a framework of your form in Word, leaving space where you’d ultimately like the Adobe fields to appear.  (Note: I use the blank lines …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now