locked
Is there a way to rename an Outlook file attachment initiated by Do.Cmd.SendObject acReport ? RRS feed

  • Question

  • Hi

    I use code to save a PDF with dynamic names like "Invoice no 345 from Sigtuna Brewery.pdf"

    To save them with names like that works fine in my code.

    DoCmd.OpenForm "CathFAKTno", acNormal, "", "", , acHidden
    ' line above opens a Form to cath Invoice No and some more

            DoCmd.OutputTo acOutputReport, "Faktura Invoice", "PDFFormat(*.pdf)", [Forms]![Alla Val]![OwnPathFakt] & [Forms]![CathFAKTno]![TextOnFakturan] & " " & [Forms]![CathFAKTno]![FAKT] & " " & [Forms]![Alla Val]![Firma] & " " & ".pdf", False, "", , acExportQualityPrint
    ' lines above save the PDF with the wanted name - works just fine

            DoCmd.SendObject acReport, "Faktura Invoice", "PDFFormat(*.pdf)", "", "", "", "", "", True, ""
    ' line above creates an Outlook email with file attachment name "Faktura Invoice.pdf"
    ' What I would like to do is to give the file the same name as in second line of code above. 
    ' So that the name could be dynamic as "Invoice no 345 from Sigtuna Brewery.pdf"
    ' But I have failed :-(

    DoCmd.Close acForm, "CathFAKTno"
    ' line above close a form

    Is there a way?


    Best // Peter Forss Stockholm and Sigtuna GMT +1.00


    Thursday, June 13, 2013 8:07 AM

Answers

  • Hi

    This is a kind of workaround. I cant find a way to rename the fileattachment. But I can put the wanted, dynamic file name, as Text string in Outlooks Subject.

    Here is my code:

    Dim SubjectLine As String

        SubjectLine= [Forms]![CatchFAKT]![TextOnFakturan] & " " & [Forms]![Alla Val]![Firma]
        Debug.Print AerendRad
        DoCmd.OutputTo acOutputReport, "Faktura R", "PDFFormat(*.pdf)", [Forms]![Alla Val]![EgenPathFakt] & [Forms]![CatchFAKT]![TextOnFakturan] & " " & [Forms]![CatchFAKT]![FAKT] & " " & [Forms]![Alla Val]![Firma] & " " & ".pdf", False, "", , acExportQualityPrint
        DoCmd.SendObject acReport, "Invoice R", "PDFFormat(*.pdf)", "", "", "", SubjectLine, "", True, ""


    Best // Peter Forss Stockholm and Sigtuna GMT +1.00

    Friday, June 14, 2013 10:34 AM