Results 1 to 4 of 4
  1. #1
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402

    rename a PDF File

    Hi All



    I have been trying to workout how to add the customer name and date to an pdf when it's e-mailed

    i have this code on the e-mail invoice button

    Private Sub E_Mail_Invoice_Click()




    'This Command Opens the report in hidden mode so that the calculations work on the Report when it's output as a PDF


    DoCmd.OpenReport "Invoice", acViewPreview, "", "", acHidden
    DoCmd.OutputTo acOutputReport, "Invoice", acFormatPDF, DLookup("FilePath", "Company Details", "CompanyID = 1") & "\Invoice.pdf" '"Filepath from company form"


    Dim OlApp As Object
    Dim objMail As Object


    On Error Resume Next 'Keep going if there is an error
    Set OlApp = GetObject(, "Outlook.Application") 'See if Outlook is open
    If Err Then 'Outlook is not open
    Set OlApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
    End If


    'Create e-mail item
    Set objMail = OlApp.CreateItem(olMailItem)


    'Set objOutlookAttach = .Attachments.Add DLookup("FilePath", "Company Details", "CompanyID = 1") & "\Invoice.pdf"
    With objMail


    'Set body format to HTML


    .BodyFormat = olFormatHTML
    .To = Me.EMail.Value
    .Subject = "Invoice Attached"
    .HTMLBody = "Dear" & " " & Me.Full_Name.Value & " " & Me.Email_Body_text.Value
    .Attachments.Add DLookup("FilePath", "Company Details", "CompanyID = 1") & "\Invoice.pdf" '("filepath= folder in which to save pdfs toas found on the company setting form")
    .Display


    End With


    Set OlApp = Nothing
    Set objMail = Nothing
    DoCmd.Close acReport, "Invoice", acSaveYes


    Me.Order_Sent_Date = Date
    End Sub

    what i am trying to do is change the name of the PDF attached from "invoice.pdf" to "fullname - order date - invoice.pdf"

    i have tried putting

    .Attachments.Add DLookup("FilePath", "Company Details", "CompanyID = 1") & "Me.Full_Name" & "me.Date_of_Order" &"\Invoice.pdf"

    when this is used the attachment is not added to the e-mail

    any help would be wonderful

    Many thanks

    Steve

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    .Attachments.Add DLookup("FilePath", "Company Details", "CompanyID = 1") & "Me.Full_Name" & "me.Date_of_Order" &"\Invoice.pdf"
    Do not use quotes around "Me.Full_Name" or "me.Date_of_Order". Using quotes creates a text string and does not use the value of the variable.

    Try this
    Create a button on the form
    Add this code to the click event of the button:

    Code:
    ' with quotes
        MsgBox DLookup("FilePath", "Company Details", "CompanyID = 1") & "Me.Full_Name" & "me.Date_of_Order" & "\Invoice.pdf"
    
    
        'Without quotes
        MsgBox DLookup("FilePath", "Company Details", "CompanyID = 1") & Me.Full_Name & Me.Date_of_Order & "\Invoice.pdf"
    Enter the data/selection for Me.Full_Name and Me.Date_of_Order. Click on the button

    Are the two message boxes different???

  3. #3
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi Ssanfu

    many thanks for getting back

    that was a great idea creating the msgbox, the option without quotes is definatly what im after but access is putting "Access PDF Documents" in front of & Me.Full_Name & Me.Date_of_Order & "\Invoice.pdf"

    Steve

  4. #4
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi

    got it to work using this

    MsgBox DLookup("FilePath", "Company Details", "CompanyID = 1") & "\" & Me.Full_Name & " " & Format(Date_Of_Order, "dd-mm-yyyy") & " " & "Invoice.pdf"

    many thanks for the msgbox pointer i tip my hat to you

    Steve

Please reply to this thread with any new information or opinions.

Similar Threads

  1. rename
    By slimjen in forum Access
    Replies: 3
    Last Post: 03-11-2013, 02:10 PM
  2. Replies: 4
    Last Post: 10-30-2012, 02:54 PM
  3. Replies: 21
    Last Post: 08-20-2012, 11:59 PM
  4. rename ole object
    By rbg in forum Access
    Replies: 0
    Last Post: 11-29-2010, 03:13 AM
  5. Have access rename a .txt file and move it
    By dh010010 in forum Programming
    Replies: 5
    Last Post: 07-22-2010, 10:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums