Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2012

    Question Unanswered: VBA to send two reports as PDF as two attachments in one emaiil

    I am trying to get two reports attached to a single email as attachments. Right now I have the two reports getting attached into two separate emails.

    Private Sub cmdEmail_Click()
    On Error GoTo Err_cmdEmail_Click

    If MsgBox("Are you ready to Email the Night Warehouse Operations Summary?", VbMsgBoxStyle.vbYesNo Or VbMsgBoxStyle.vbExclamation, "Email Report") = vbYes Then

    DoCmd.SendObject acReport, "rptNight_Summary_Report", "PDFFormat(*.pdf)", "emailaddress", "", "", "Night Warehouse Operations Summary", "Please see attached Night Warehouse Operations Summary", False, ""
    DoCmd.SendObject acReport, "rptAttendance", "PDFFormat(*.pdf)", "emailaddress", "", "", "Night Warehouse Operations Summary", "Please see attached Night Warehouse Attendance Summary", False, ""
    Exit Sub
    End If
    Exit Sub
    MsgBox Err.Description
    Resume Exit_cmdEmail_Click
    End Sub
    how do i combine the two docmd.sendobject's to make one? Haven't had much luck trying.

  2. #2
    Join Date
    Aug 2012
    Solved with this:

    Rem <!-- Make sure the Microsoft Object xx.0 Reference Library is enabled & _
    (found under Tools>References in the VBA Editor) -->

    Dim objOutlook As Outlook.Application
    Dim objEmail As Outlook.MailItem
    Dim strAttach1 As String
    Dim strAttach2 As String
    Dim strAttach3 As String
    Dim strAttach4 As String
    Dim strAttach5 As String

    Set objOutlook = CreateObject("Outlook.application")
    Set objEmail = objOutlook.CreateItem(olMailItem)

    'Output Reports
    Rem <!-- change "Reportx" to match the report names you wish to export. & _
    IMPORTANT: Make sure the location you select to save your reports to exists, Access will & _
    not create the folders for you. -->
    DoCmd.OutputTo acOutputReport, "rptNightSummaryReport", acFormatPDF, "C:\NightSummaryReport.pdf", False
    DoCmd.OutputTo acOutputReport, "rptactivity_Summary", acFormatPDF, "C:\ActivitySummary.pdf", False

    'Set Attachments
    Rem <!-- make sure to correlate the attachments to each of the reports you wish to send -->
    strAttach1 = "C:\NightSummaryReport.pdf"
    strAttach2 = "C:\ActivitySummary.pdf"

    'Generate email
    With objEmail
    .To = ";"
    .Subject = "Night Warehouse Productivity Reports"
    .Body = "Night warehouse productivity reports"
    .Attachments.Add strAttach1
    .Attachments.Add strAttach2

    End With

    'Remove attachments from drive
    Kill strAttach1
    Kill strAttach2
    Please not this is not my code. I altered it to make it work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts