469,353 Members | 2,113 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,353 developers. It's quick & easy.

Sending an Access Report as an attachment via Outlook automatically

1
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...
Expand|Select|Wrap|Line Numbers
  1. Dim objOutlook As New Outlook.Application
  2. Dim ObjOutlookMsg As Outlook.MailItem
  3.  
  4. Set ObjOutlookMsg = objOutlook.CreateItem(olMailItem)
  5. With ObjOutlookMsg
  6. .To = aRecipients
  7. .Subject = "test"
  8. .Body = "hi"
  9. .Body = "Body of email"
  10. .Attachments = aAttachments ( I believe this is where I need help)
  11. .Send
  12. End With
  13. Set ObjOutlookMsg = Nothing
  14. Set objOutlook = Nothing
Jan 23 '12 #1
4 12339
ADezii
8,800 Expert 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. 'Set a Reference to the Microsoft Outlook ?X.X Object Library
  2. Dim strReportName As String
  3. Dim oLook As Object
  4. Dim oMail As Object
  5. Dim olns As Outlook.NameSpace
  6. Dim strTO As String
  7. Dim strMessageBody As String
  8. Dim strSubject As String
  9.  
  10. strReportName = "rptEmployees"
  11. DoCmd.OutputTo acOutputReport, strReportName, acFormatRTF, CurrentProject.Path & _
  12.                "\" & strReportName & ".rtf", False
  13.  
  14. Set oLook = CreateObject("Outlook.Application")
  15. Set olns = oLook.GetNamespace("MAPI")
  16. Set oMail = oLook.CreateItem(0)
  17.  
  18. '*********************** USER DEFINED SECTION ************************
  19. strTO = "JDoe@aol.com"
  20. strMessageBody = "Here is the Report that you requested"
  21. strSubject = "Test Project for Attaching Access"
  22. '*********************************************************************
  23.  
  24. With oMail
  25.  .To = strTO
  26.  .Body = strMessageBody
  27.  .Subject = strSubject
  28.  .Attachments.Add CurrentProject.Path & "\" & strReportName & ".rtf"
  29.    '.Display
  30.      .Send
  31. End With
  32.  
  33. Set oMail = Nothing
  34. Set oLook = Nothing
Jan 24 '12 #2
it is quite simple really

Expand|Select|Wrap|Line Numbers
  1. 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
Jan 25 '12 #3
ADezii
8,800 Expert 8TB
As stated by the OP:
The SendObject method is not an option.
Jan 25 '12 #4
@ADezii
Hello, how would you modify this to send more than one report and also add more email recipients?
Mar 5 '14 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Aby Mathews | last post: by
1 post views Thread by Dirk Goossens | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.