Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am looking to embed a report in the body of an email as text or html 1

Status
Not open for further replies.

Johnnycat1

Programmer
May 4, 2005
71
US
I am trying to simplify sending reports via email and rather than using the send object method and having an rtf or snp snapshot attachment I would like to know if anyone has come up with a straightforward way to embed the report directly in the body of the email.

One possible hickup is that the report/s also include subreports.

Any help is appreciated.
 
You can write the report to RTF or HTML and read it in to the email. A few notes:

Code:
Sub RTFBodyX()
Const ForReading = 1, ForWriting = 2, ForAppending = 3

Dim fs, f
Dim RTFBody, strTo
Dim MyApp As New outlook.Application
Dim MyItem As outlook.MailItem

'DoCmd.OutputTo acOutputReport, "Report1", acFormatRTF, "Report1.rtf"
DoCmd.OutputTo acOutputQuery, "Query1", acFormatHTML, "Query1.htm"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("Query1.htm", ForReading)
'Set f = fs.OpenTextFile("Report1.rtf", ForReading)
RTFBody = f.ReadAll
f.Close

Set MyItem = MyApp.CreateItem(olMailItem)
With MyItem
   .To = "a@b.c"
   .Subject = "Subject"
   '.Body = RTFBody
   .HTMLBody = RTFBody
End With
MyItem.Display
End Sub
 
Remou if you are still watching this thread (or anyone with some insite)...

The code that you posted looks good but I am getting a compile error "User defined type not defined".

The error is at line

Dim MyApp As New outlook.Application

I can see that I do not have a "Outlook.Application" class/type. Do I need a module to define the Outlook.Application type? I would assume that the module would also define the next line "Dim MyItem As outlook.MailItem"

Again, I really appreciate the help.
 
You need to reference (Tools->Reference) the Microsoft Outlook x.x Object Library for the snippet above to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top