Results 1 to 6 of 6
  1. #1
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186

    Include name to a attached Report with DoCmd.SendObject

    Hi everyone,



    Quick question...

    I have an issue with a code I have programmed, I want to add an specific name for the report attached, in my code the name is "ReportName"

    Does somebody know how to add this to the DoCmd.SendObjetct?

    The name include into the report is the "Report Name created originally"

    Thanks for your support!!!!


    ***********************************

    Private Sub SendReportPDFcmd_Click()


    Dim ReportName As String
    Dim stDocName As String


    ReportName = "Report NC " & Me.Code
    stDocName = "NC_Report_PDF"

    DoCmd.SendObject acSendReport, stDocName, acFormatPDF, , , , "No Conformidad Folio: " & Me.Code, "Se generó la No Conformidad con Folio: " & Me.Code


    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    SendObject does not allow that. Would have to first save report with that name.

    Alternative is to use Outlook automation code. Use OutputTo to save report as PDF then attach pdf to email object.
    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
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Hi June7

    How do you inlcude the reported created as an attachment?, I understand I have to use DoCmd.SendObject

    **********************

    Dim stDocName As String
    Dim stReportName As String
    Dim stLinkCriteria As String
    Dim stFileName As String

    stDocName = "Diagram"
    stReportName = "Diagram AB "


    stFileName = CurrentProject.Path & "" & stReportName & Me.ID & ".pdf" 'set the file name for the new PDF

    DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, stFileName, True 'HOW Can I attach this to Outlook automatically?
    DoCmd.SendObject acSendReport, stDocName, acFormatPDF, , , , "NC Report: " & Me.ID, "NC Report with ID: " & Me.ID

    End Sub

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    No, not SendObject, Outloook automation. This means declaring and setting and manipulating variables for Outlook objects. This is a common topic.

    The PDF will take name of report Caption property if it has an input. So an alternative is code opens report in Design view, sets the Caption property, saves report with this design change, then run SendObject.
    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
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Oh I see!
    Do you have an example of this?

    I am not a full expert coding :$

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Of what - Outoolk automation? You could Google or search this forum. However, example from my code that sends multiple emails to addresses in a recordset:
    Code:
    Private Sub Email()
    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Dim body As String, rs As Recordset
    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    Set rs = CurrentDb.OpenRecordset("SELECT UmpID, Email FROM Umpires WHERE ID=1")
    Do While Not rs.EOF
        With MailOutLook
        '    .BodyFormat = olFormatHTML
            .To = rs!Email
            ''.cc = ""
            ''.bcc = ""
        '    .Attachments.Add "filepath\filename"
            .Subject = "Test : " & rs!UmpID
            body = "<table style='text-align:right;border:1px solid black;font-family:calibri;border-collapse:collapse;padding:15px'><tr style='background:yellow;mso-highlight:yellow'>" & _
                "<th>No</th><th>Client</th><th>Date</th><th>PR</th><th>Currency</th><th>Amt</th></tr>" & _
                "<tr><td>12345</td><td>Jones</td><td>12Dec2017</td><td>ABC</td><td>US</td><td>2000</td></tr>" & _
                "<tr><td>67890</td><td>Finkbiner</td><td>12Dec2017</td><td>ABC</td><td>US</td><td>1000</td></tr></table>"
            body = "<HTML style='font-family:calibri'><Body><font face='calibri'><a href='C:\Users\Owner\June\Forums'><img SRC=C:\Users\Owner\June\DOT\Lab\Editing\LABDB.png></a><br>" & _
                "<font color='red' size='1'>&nbsp;&nbsp;&nbsp;&nbsp;READ THIS EMAIL COMPLETELY</font><br>" & _
                body & _
                "<br><b>Please confirm or I will kick you.</b><br>" & _
                "</font></Body></HTML>"
            .Display
            .body = "Test" & vbCrLf & "multi-line"
            'following allows including Outlook email signature
            '.HTMLBody = Replace(.HTMLBody, "<div class=WordSection1><p class=MsoNormal><o:p>", "<div class=WordSection1><p class=MsoNormal><o:p>" & body)
            '.HTMLBody = "Test HL: <a href='C:\Users\" & Environ("USERNAME") & "\Desktop\Shortcut to Main in Umpires.accdb.MAF'>Link description here</a>"
        '    .Send
        End With
        'MsgBox "Continue"
        rs.MoveNext
    Loop
    End Sub
    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.

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

Similar Threads

  1. DoCmd.SendObject Stops Macro When Report is not Created
    By Oxygen Potassium in forum Access
    Replies: 2
    Last Post: 09-22-2016, 06:53 AM
  2. Replies: 15
    Last Post: 06-29-2015, 11:12 AM
  3. Replies: 11
    Last Post: 09-17-2013, 06:29 PM
  4. Replies: 3
    Last Post: 09-09-2013, 01:48 PM
  5. Replies: 10
    Last Post: 03-26-2012, 08:17 PM

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