How do you send multiple reports with the docmd.sendobject?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anoble1
    New Member
    • Jul 2008
    • 246

    #1

    How do you send multiple reports with the docmd.sendobject?

    Hi,
    I have a database that sends out emails to users that contains a few reports. I am trying to come up with a way that will combine the reports in 1 email. Is that possible?

    Here is my code.
    Code:
    DoCmd.SendObject acOutputReport, "rptPSSREmail" & "rptPSSRMonthlyLaborSalesbyPSSR", acFormatPDF, "myemail.com"
    I get an error with the code above because I am trying to combine 2 reports. How do I do this? I am trying to attach 3 reports to one email.

    Thanks,
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Is Microsoft Outlook your E-Mail Client?

    Comment

    • anoble1
      New Member
      • Jul 2008
      • 246

      #3
      Yes, it is MS Outlook

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        1. Save/Export each Report as a *.pdf.
        2. Open Microsoft Outlook using Automation Code.
        3. Attach each Exported Report (*.pdfs) to the E-Mail which results in an E-Mail being sent to a single Recipient, with multiple Attachments.

        Comment

        • anoble1
          New Member
          • Jul 2008
          • 246

          #5
          The code I have attaches one attachment in Outlook when it opens, but not the 3 attachments. I am not sure how to feed 3 reports into 1 email.

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            The following Code will:
            1. Create a New Instance of Microsoft Outlook.
            2. Loop thru every Report in the Database and if it begins with rptPSSR, namely (rptPSSR*) Export that Report in *.pdf Format to the same Folder that the Database is in, Attach that Report to an E-Mail with previously defined Parameters, then finally Delete the *.pdf.
            3. Once all Reports in the form of *.pdfs have been attached, opens the Outlook Window with the appropriate To:, From:, Subject:, and Body: Fields populated along with Multiple Attachments.
            4. The Code has been tested and is fully operational'
              Code:
              'First, set a Reference to the Microsoft Outlook XX.X Object Library
              Dim aob As AccessObject
              Dim oLook As New Outlook.Application
              Dim oMail As Outlook.MailItem
              Dim olns As Outlook.Namespace
              
              Set olns = oLook.GetNamespace("MAPI")
              
              Set oMail = oLook.CreateItem(0)
              
              With oMail
                .To = "MyEMail.com"
                .Body = "Attached, please find a Summary Report for your review."
                .Subject = "My Subject"
              End With
              
              For Each aob In CurrentProject.AllReports
                If Left$(aob.Name, 7) = "rptPSSR" Then
                  DoCmd.OutputTo acOutputReport, aob.Name, acFormatPDF, CurrentProject.Path & _
                                 "\" & aob.Name & ".pdf", False
                    oMail.attachments.Add CurrentProject.Path & "\" & aob.Name & ".pdf"
                      Kill CurrentProject.Path & "\" & aob.Name & ".pdf"
                End If
              Next
              
              oMail.Display

            Comment

            Working...