Solved

With SendObject, how do you send html formated email ?

Posted on 2002-03-09
11
625 Views
Last Modified: 2010-08-05
In MSaccess I create an email using:
DoCmd.SendObject acReport, stDocName, acFormatHTML, Cust_email, , , MyTitle , MyWaffle

Where Mywaffle is a long text string that forms the message of the email.

This is plain text using vbcrlf and vbtab to lay out the message.

I now want to create the message in html to get it to look better; how do I do that?

How do you imbed the html document into the email message?

I have created a template file, but not sure how to get the data (using visual basic) to the variable
ie how do a populate <!--AcessTemplate_Body-->      with data?

Or do you just put the html tags in the string (mywaffle), if so what setting in outlook do you need to change to get it to work?
0
Comment
Question by:perrybond
  • 7
  • 3
11 Comments
 
LVL 6

Accepted Solution

by:
xSinbad earned 300 total points
ID: 6853734
You could create a html file and then attach it to an email like this;

use OPEN to create the file

open "filename.html" for input as #1
write #1, MyWaffle ' String with html tags in it
close #1

and then using some code like this to attach it to an email.

Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
   Dim objOutlook As Outlook.Application
   Dim objOutlookMsg As Outlook.MailItem
   Dim objOutlookRecip As Outlook.Recipient
   Dim objOutlookAttach As Outlook.Attachment
   
   ' Create the Outlook session.
   Set objOutlook = CreateObject("Outlook.Application")
   
   ' Create the message.

   Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
   
   With objOutlookMsg
        ' Add the To recipient(s) to the message.
        Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
        objOutlookRecip.Type = olTo
       
        ' Add the CC recipient(s) to the message.
        Set objOutlookRecip = .Recipients.Add("Michael Suyama")
        objOutlookRecip.Type = olCC
       
       ' Add the BCC recipient(s) to the message.

        Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
        objOutlookRecip.Type = olBCC
       
       ' Set the Subject, Body, and Importance of the message.
       .Subject = "This is an Automation test with Microsoft Outlook"
       .Body = "This is the body of the message." & vbCrLf & vbCrLf
       .Importance = olImportanceHigh  'High importance
               
       ' Add attachments to the message.
       If Not IsMissing(AttachmentPath) Then

           Set objOutlookAttach = .Attachments.Add(AttachmentPath)
       End If
       
       ' Resolve each Recipient's name.
       For Each objOutlookRecip In .Recipients
           objOutlookRecip.Resolve
       Next
       
       ' Should we display the message before sending?
       If DisplayMsg Then
           .Display
       Else
           .Send
       End If

   End With
   Set objOutlook = Nothing
End Sub
0
 

Author Comment

by:perrybond
ID: 6854355
Sorry, I did not want to add an attachment, I want to send an email where the body of the email is using html.
I receive emails html formatted so I know it is possible.
0
 
LVL 4

Expert Comment

by:wesleystewart
ID: 6855571
"Where Mywaffle is a long text string that forms the message of the email."

All you need to do is build a string that contains the html-formatted text and pass it as MyWaffle.

Are you familiar with html tags?

Wes
0
 

Author Comment

by:perrybond
ID: 6855997
Yes, I have no problem with the html tags.
I have written the hrml in a txt file, checked it was OK, cut and pasted it into some VBA behind MSaccess, used this as the string 'MyWaffle', edited it to include the variables to display the live data, then used sendobject.

However, as Outlook opened, the text string was displayed as is, not html formatted.

I now assume from your reply that I am doing it right in the VBA and the problem occours with the settings within outlook.

I will look into this and report back

Thanks
0
 

Author Comment

by:perrybond
ID: 6856074
This is really turning into an Outlook question, not MSaccess

In Outlook I've changed the mail settings in the options to rich text (html) and if a write a new email, it is html formatted.

When I use sendObject, the new email pops up as plain text.

Should I go and ask this question under Outlook?

Perry
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:perrybond
ID: 6856109
This is really turning into an Outlook question, not MSaccess

In Outlook I've changed the mail settings in the options to rich text (html) and if a write a new email, it is html formatted.

When I use sendObject, the new email pops up as plain text.

Should I go and ask this question under Outlook?

Perry
0
 
LVL 4

Expert Comment

by:wesleystewart
ID: 6856523
Rather than struggle with Docmd.Sendobject, you could use xSinbad's code to automate Outlook.  This gives you much greater control anyway.

Instead of working with the .body property, however, you will work with the .htmlbody property.  This should produce the output you're looking for.  It will look something like this:

.Subject = "This is an Automation test with Microsoft Outlook"
.HTMLBody = "This should be <b>bold</b>."
.Importance = olImportanceHigh  'High importance

This way you don't need to send an attachment.

Wes
             
     

0
 

Author Comment

by:perrybond
ID: 6856935
Thanks, this sounds a good idea, only I cannot get xsinbads code to work

I cannot even get the dims to compile.

i have some MAPI stuff that is working and creating emails; I don't really understand how it works, but cannot find any way of using html with it.

If someone could help me getting xsindads code working i would be most gratefull.

we are using MSaccess98 and Outlook98

0
 
LVL 4

Expert Comment

by:wesleystewart
ID: 6857063
From any module in design view, click >>Tools>>References.  You'll need to find a reference for Outlook 98 Type Library.  Activate this reference and all your Outlook object declarations will compile.

Wes

0
 

Author Comment

by:perrybond
ID: 6857458
Great, cracked it !!!
Thanks xsinbad for the code and thanks wes for the help.
I know I can split points, but I don't know how !
0
 

Author Comment

by:perrybond
ID: 6880023
Thanks for the code, it just took me a while to figure out it WAS what I wanted
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now