brorick
10-15-2007, 10:34 PM
I am attempting to embed a RTF document into the body of my email. I have successfully done this with plain and HTML, but my current project requires me to use an RTF file. I used the following code and for some unexplained reason my email shows the following instead of the content of the RTF document. I have searched and searched the internet with no success. I am hoping someone can assist me. : pray2:
Once the problem is resolved I hope to then figure out how to embed two or three RTF documents at the same time into the body of the email. Thank you in advance for your help.
{\rtf1\ansi\ansicpg1252\paperh20160\paperw12240\margl720\margr720\margt720\ margb747\psz5{\colortbl\red0\green0\blue0;\red255\green255\blue255;\red128\ green0\blue0;}{\fonttbl\f0\fcharset0\fnil Arial;\f1\fcharset0\fnil Arial;\f2\fcharset0\fnil Arial;\f3\fcharset0\fnil Arial;}\pard\plain\tqr\tx7560\tx7680\tx9060{\plain\tab\fs16\b\f1\cf0\cb1 Date Issue Reported:\
Sub SendRTFMessage(Optional AttachmentPath)
Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim strLocalPath As String
Set fso = New FileSystemObject
DoCmd.OutputTo acOutputReport, "Rpt_Tasks", acFormatRTF, "C:\Report2Word.rtf"
strLocalPath = "C:\Report2Word.rtf"
Set MyBody = fso.OpenTextFile(strLocalPath, ForReading, False, TristateUseDefault)
MyBodyText = MyBody.ReadAll
Set objOutlook = New Outlook.Application
Set db = CurrentDb()
Set MailList = db.OpenRecordset("Qry_Tasks")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("JohnDoe@Yahoo.com")
objOutlookRecip.Type = olTo
Set objOutlookRecip = .Recipients.Add("TomSmith@Yahoo.com")
objOutlookRecip.Type = olCC
.Subject = "Current Task"
.BodyFormat = olFormatRichText
.Body = MyBodyText
.Importance = olImportanceHigh
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
objOutlookMsg.Display
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
Once the problem is resolved I hope to then figure out how to embed two or three RTF documents at the same time into the body of the email. Thank you in advance for your help.
{\rtf1\ansi\ansicpg1252\paperh20160\paperw12240\margl720\margr720\margt720\ margb747\psz5{\colortbl\red0\green0\blue0;\red255\green255\blue255;\red128\ green0\blue0;}{\fonttbl\f0\fcharset0\fnil Arial;\f1\fcharset0\fnil Arial;\f2\fcharset0\fnil Arial;\f3\fcharset0\fnil Arial;}\pard\plain\tqr\tx7560\tx7680\tx9060{\plain\tab\fs16\b\f1\cf0\cb1 Date Issue Reported:\
Sub SendRTFMessage(Optional AttachmentPath)
Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim strLocalPath As String
Set fso = New FileSystemObject
DoCmd.OutputTo acOutputReport, "Rpt_Tasks", acFormatRTF, "C:\Report2Word.rtf"
strLocalPath = "C:\Report2Word.rtf"
Set MyBody = fso.OpenTextFile(strLocalPath, ForReading, False, TristateUseDefault)
MyBodyText = MyBody.ReadAll
Set objOutlook = New Outlook.Application
Set db = CurrentDb()
Set MailList = db.OpenRecordset("Qry_Tasks")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("JohnDoe@Yahoo.com")
objOutlookRecip.Type = olTo
Set objOutlookRecip = .Recipients.Add("TomSmith@Yahoo.com")
objOutlookRecip.Type = olCC
.Subject = "Current Task"
.BodyFormat = olFormatRichText
.Body = MyBodyText
.Importance = olImportanceHigh
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
objOutlookMsg.Display
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub