Sending an Access Report as an attachment via Outlook automatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nefsay
    New Member
    • Jan 2012
    • 1

    Sending an Access Report as an attachment via Outlook automatically

    I'm trying to send an existing Access Report as an attachment via MS Outlook. The SendObject method is not an option.

    Since, the report i'm trying to send is an access object it is not stored at a particular path on the PC/network.

    Any help would be greatly appreciated! This is what I have tried so far but have been running out of options...
    Code:
    Dim objOutlook As New Outlook.Application
    Dim ObjOutlookMsg As Outlook.MailItem
    
    Set ObjOutlookMsg = objOutlook.CreateItem(olMailItem)
    With ObjOutlookMsg
    .To = aRecipients
    .Subject = "test"
    .Body = "hi"
    .Body = "Body of email"
    .Attachments = aAttachments ( I believe this is where I need help)
    .Send
    End With
    Set ObjOutlookMsg = Nothing
    Set objOutlook = Nothing
    Last edited by NeoPa; Jan 25 '12, 12:04 AM. Reason: Added mandatory [CODE] tags for you
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Here is Code that Saves a Report as an *.rtf File, Attaches the Report to an E-Mail addressed to JDoe@aol.com, then Sends the E-Mail via Outlook:
    Code:
    'Set a Reference to the Microsoft Outlook ?X.X Object Library
    Dim strReportName As String
    Dim oLook As Object
    Dim oMail As Object
    Dim olns As Outlook.NameSpace
    Dim strTO As String
    Dim strMessageBody As String
    Dim strSubject As String
    
    strReportName = "rptEmployees"
    DoCmd.OutputTo acOutputReport, strReportName, acFormatRTF, CurrentProject.Path & _
                   "\" & strReportName & ".rtf", False
      
    Set oLook = CreateObject("Outlook.Application")
    Set olns = oLook.GetNamespace("MAPI")
    Set oMail = oLook.CreateItem(0)
      
    '*********************** USER DEFINED SECTION ************************
    strTO = "JDoe@aol.com"
    strMessageBody = "Here is the Report that you requested"
    strSubject = "Test Project for Attaching Access"
    '*********************************************************************
      
    With oMail
     .To = strTO
     .Body = strMessageBody
     .Subject = strSubject
     .Attachments.Add CurrentProject.Path & "\" & strReportName & ".rtf"
       '.Display
         .Send
    End With
      
    Set oMail = Nothing
    Set oLook = Nothing

    Comment

    • ChrisPadgham
      New Member
      • Jan 2012
      • 11

      #3
      it is quite simple really

      Code:
      DoCmd.SendObject acSendReport, "MyReport", acFormatRTF, "theemail@emails.com", , , "Here is your report"
      note if you are using a later version of access you can use acFormatPDF to present your report in PDF format

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        As stated by the OP:
        The SendObject method is not an option.

        Comment

        • ahafenbr
          New Member
          • Mar 2014
          • 1

          #5
          Multiple reports, receipting

          Originally posted by ADezii
          As stated by the OP:
          Hello, how would you modify this to send more than one report and also add more email recipients?

          Comment

          Working...