Solved

With SendObject, how do you send html formated email ?

Posted on 2002-03-09
11
626 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

867 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

21 Experts available now in Live!

Get 1:1 Help Now