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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format email from Access Form 1

Status
Not open for further replies.

DenverMarc

Technical User
Apr 27, 2005
33
US
Hi,

Is it possible to make the body of an email created from an Access form Rich Text rather than Plain Text? I'm in Access 2000. Here's some of the code I'm using:

Code:
Dim stText As String
Dim stLists As String
Dim stOrderNum As String
Dim stMailer As String
Dim stOffer As Variant
Dim stNames As Variant
Dim stValue As Variant
Dim stNotes As Variant
Dim stSalesperson As String
Dim stSelects As Variant
Dim stNewMailer As Variant

stLists = Me.List
stOrderNum = Me.OrderNum
stMailer = Me.Mailer.Column(2)
stOffer = Me.Offer
stNames = Me.NumberNames
stValue = Me.OrderValue
stNotes = Me.Notes
stSalesperson = Me.SalesRep.Column(1)
stSelects = Me.Selects
stNewMailer = Me.NewMailer

stText = "Please respond to this email with your approval or denial of the following..." & Chr$(13) & Chr$(13) & _
         "Lists: " & stLists & Chr$(13) & Chr$(13) & _
         "Order: " & stOrderNum & Chr$(13) & Chr$(13) & _
         "Mailer: " & stMailer & Chr$(13) & Chr$(13) & _
         "Offer: " & stOffer & Chr$(13) & Chr$(13) & _
         "Number of Names: " & Format(stNames, "#,###,###") & Chr$(13) & Chr$(13) & _

...........

DoCmd.SendObject , , acFormatRTF, , , , , stText, -1

I think the "acFormatRTF" refers to an attached object, but I'm trying to make the actual email itself be Rich Text.

Is that possible?

Thanks,

Marc
 
Hi Marc,

Can't say I'm the right person to reply, but I thought I may as well try & give you benefit of experience at least!

As far as I can tell (which isn't far!), I wouldn't have thought you could specify Rich Text in that code. I could be very wrong though. However, I do a similar thing with creating objects for Outlook & when you specify the subject text, you can use "HTMLBody =" instead of "Body =" & use HTML commands to create different fonts, colours, etc. Essentially, rich text.

Of course, if you don't want to use Outlook you're still at square one!
 
Thanks Najemikon,

I was afraid it couldn't be done.

Thanks,

Marc
 
I used Najemikon's suggesting of changing ".Body" to ".HTMLBody", and simply changed what I had to send to HTML format before sending. Worked quite nicely.

-Rafael
 
It is possible to output a report in rich text format or html and read it back in, if you can use Outlook.
Code:
Sub RTFBody()
Dim RTFBody
Dim MyApp As New outlook.Application
Dim MyItem As outlook.MailItem

'Output RTF
DoCmd.OutputTo acOutputReport, "Report1", acFormatRTF, "Report1.rtf"
'Output HTML
'DoCmd.OutputTo acOutputQuery, "Query1", acFormatHTML, "Query1.htm"

'Read file in to RTF body
Open "Report1.rtf" For Input As #1
Do While Not EOF(1)
    Line Input #1, TextLine
    RTFBody = RTFBody & TextLine
Loop
Close #1

'Create email
Set MyItem = MyApp.CreateItem(olMailItem)
With MyItem
   .To = "me@co.com"
   .Subject = "Subject"
'For RTF
   .Body = RTFBody
'For HTML
   '.HTMLBody = RTFBody
End With
'Show email
MyItem.Display
End Sub
 
I'm not sure I follow what you all are saying. I don't have an attachment or report, I'm just trying to make the email itself be rich text. I don't have a "body" to change to "RTFBody".

Thanks,

Marc
 
No, Marc, he isn't creating an attachment. I like it, Remou! Very sneaky.

If I understand it correctly, this is what the code is doing:

1) Essentially create the email as a standard Access report, with all the formatting you want.
2) Use the code to save that report as a Rich Text File.
3) Read the contents of the file back in to the code (becomes the variable RTFbody), which should retain the formatting.
4) Then you use the very simple line .HTMLbody = RTFBody (your variable).

As I said before, if you want to format the text as Rich Text, you have to include all the HTML commands & the code becomes a nightmare. But when you use this method & save it as a report/file first, those control characters are done for you, so when you copy it back in, they're already there & you don't have to worry about them.

Great stuff! Hope I understood that correctly because I can't wait to try it now.


Jon
 
Najemikon
If you output the report as RTF, just use .Body
.HTMLBody is for HTML output. If RTF output does not work for any reason, try the HTML option. Enjoy :)
 
There is a MailItem property for 'BodyFormat', just set this property to:

olFormatHTML
olFormatPlain
olFormatRichText
olFormatUnspecified

You can also use the HTMLBody property, which set's the message body as HTML code. Setting this value automatically changes the message's 'Inspector' object's 'EditorType' property to olEditorHTML.

Sean.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top