Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 651
  • Last Modified:

With SendObject, how do you send html formated email ?

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
perrybond
Asked:
perrybond
  • 7
  • 3
1 Solution
 
xSinbadCommented:
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
 
perrybondAuthor Commented:
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
 
wesleystewartCommented:
"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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
perrybondAuthor Commented:
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
 
perrybondAuthor Commented:
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
 
perrybondAuthor Commented:
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
 
wesleystewartCommented:
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
 
perrybondAuthor Commented:
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
 
wesleystewartCommented:
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
 
perrybondAuthor Commented:
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
 
perrybondAuthor Commented:
Thanks for the code, it just took me a while to figure out it WAS what I wanted
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now