Results 1 to 7 of 7
  1. #1
    Flytkjaer's Avatar
    Flytkjaer is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2012
    Location
    Denmark
    Posts
    14

    Send object as PDF with caption name

    Hi i'm looking for a soloution where i can get an E-mail botton to send an e-mail with a unique named pdf file attached.



    Here is my VBA for the calling button.

    Code:
    Private Sub E_Mail_Ordre_Click()
    On Error GoTo Err_Send_bestilling_Click
            Dim stDocName As String
        
        DoCmd.SendObject _
        acSendReport, _
        "Sparepart_Return_Order", _
        acFormatPDF, _
        "E@Mail.here", _
        , _
        , _
        "Sparepart order No: " & [Ordre_Hoved_Id], _
        "Messages body.", _
        False
     
    Exit_Send_bestilling_Click:
        Exit Sub
    Err_Send_bestilling_Click:
        MsgBox Err.Description
        Resume Exit_Send_bestilling_Click
        
    End Sub
    Here is my VBA for the report which i would like to be attached to the mail.

    Code:
    Private Sub Report_Activate()
    Me.Caption = "Return Of Spareparts No:" & [Forms]![Retur_Ordre_Hoved]![Ordre_Hoved_Id]
    End Sub
    When i hit the e-mail button, Access process my request and send out the mail, allthough i would have to allow the outgoing mail from access. but the problem is that the attached pdf file are named after report name not the title.
    I would like to end up with an attachment named something like this: Sparepart_Order_No_x.pdf

    Thanks for your assistance in advanvce.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Google: Access VBA email report as pdf

    I don't think SendObject gives option to name the attachment. I use this method for email: http://forums.aspfree.com/microsoft-...ro-447084.html

    Might have to save the report as a pdf first, see
    http://www.access-programmers.co.uk/...d.php?t=141517
    http://database.ittoolbox.com/groups...a-code-1463260
    http://www.granite.ab.ca/access/emai...ttachments.htm
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Flytkjaer's Avatar
    Flytkjaer is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2012
    Location
    Denmark
    Posts
    14
    Hi June7

    Maybe your right, but would it be possible to pass the title along to the report in any otherway, and how is it done?

    I think the problem in my initial project, is that the report never opens during this operation.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The only 'other way' I know of is to save the report to PDF with name of your preference in one action and then attach the saved PDF to email in another action. The referenced links have code samples.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Flytkjaer's Avatar
    Flytkjaer is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2012
    Location
    Denmark
    Posts
    14
    Hi June7

    For those of you who would like Access to sendout an e-mail with an attached pdf file, where the file has been given as unique name. Here is how to do it!
    This code opens the report, renames it and export it to you mail client. Press the send button and the mail is send and the report closes.

    There wouldl be promted for send or if you change
    DoCmd.SendObject acSendReport, stReport, "PDFFormat(*.pdf)", stEmail, , , stSubject, stEmailMessage, True,
    To False
    You will be promted for Allow or Disallow security warning.


    Code:
    Private Sub E_Mail_Ordre_Click()
    On Error GoTo Err_Send_bestilling_Click
        Dim stReport As String
        Dim stWhere As String
        Dim stEmail As String
        Dim stSubject As String
        Dim stEmailMessage As String
        Dim ReportCap As String
        
        stEmailMessage = "Message goes here." & vbCrLf & vbCrLf & "Best Regards" & vbCrLf & "Sender."   'E-mail body
        stSubject = "Subject goes here: " & [Ordre_Hoved_Id] 'Email Subject
        stReport = "Sparepart_Return_Order" 'Original name of the Report
        ReportCap = "Spare parts return"    'Current Report Caption
        stEmail = "e-mail@e-mail.xx"    'E-mail adresses or (Me.E-mail fieldname)
        DoCmd.OpenReport stReport, acViewPreview, "", stWhere, acWindowNormal, ""   'Opens the report
        Reports!Sparepart_Return_Order.Caption = "Output filename:" & [Ordre_Hoved_Id]    'Renames the Report
        DoCmd.SendObject acSendReport, stReport, "PDFFormat(*.pdf)", stEmail, , , stSubject, stEmailMessage, True, "" 'Send out the E-mail
        DoCmd.Close acReport, stReport, acSaveNo
           
        
        
    Exit_Send_bestilling_Click:
        Exit Sub
    Err_Send_bestilling_Click:
        MsgBox Err.Description
        Resume Exit_Send_bestilling_Click
        
    End Sub

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Congratulations! Ingenious! Glad you figured out a solution.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Flytkjaer's Avatar
    Flytkjaer is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2012
    Location
    Denmark
    Posts
    14
    Hmm. i wonder why i left this in my code.

    Dim stWhere As String

    And

    DoCmd.OpenReport stReport, acViewPreview, "", stWhere, acWindowNormal, "" 'Opens the report


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

Similar Threads

  1. Replies: 1
    Last Post: 09-03-2011, 07:01 PM
  2. Using a Labels Caption Programmatically
    By ksmith in forum Programming
    Replies: 2
    Last Post: 10-12-2010, 01:10 PM
  3. To feild in send object from Form
    By forrestapi in forum Forms
    Replies: 16
    Last Post: 07-29-2010, 03:05 PM
  4. send object report
    By ldappa in forum Access
    Replies: 1
    Last Post: 07-19-2010, 10:10 AM
  5. Send Object to addresses in table
    By cm-net in forum Access
    Replies: 1
    Last Post: 04-26-2010, 02:36 PM

Tags for this Thread

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