Solved

Code not attaching .pdf file

Posted on 2013-12-05
11
633 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 2
11 Comments
 
LVL 37

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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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
 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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 …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

691 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