How to get Access to open Outlook in HTML instead of Plain Text (1 Viewer)

WalbergB

New member
Local time
Today, 02:00
Joined
Nov 21, 2024
Messages
3
I have a simple, 2-table database for a small non-profit that keeps track of donors (tblDonor) and their donations (tblDonation). Using the DoCmd.SendObject command, I have Access open Outlook with the TO and SUBJECT lines filled in from the database and the donor's tax receipt attached. I add a note and send the email. This is a portion of the VBA code:

-----------------------------------
'Emails or prints receipt
Dim continue As Integer
continue = MsgBox("Check receipt details before proceeding.", vbOKCancel, "Donor's tax receipt")
If continue = vbOK Then

If Not IsNull(Forms!frmDonorDonation!EmailAddress) Then
DoCmd.SendObject acSendReport, "rptTaxReceipt", acFormatPDF, Forms!frmDonorDonation!EmailAddress, , "bwccr1955@gmail.com", "Tax Receipt Attached"
Else
DoCmd.RunCommand acCmdPrint
End If

Else
Exit Sub

End If

---------------------------

The problem is that Access opens Outlook in Plain Text format. I would prefer HTML format because I have a signature that includes the non-profit's logo. I have Outlook's " Compose messages" set for HTML format, so that's not the problem. When I Googled this problem, I get a solution that involes a massive amount of VBA code that doesn't use the DoCmd.SendObject command. Don't be overly impressed by my use of VBA code above. I adapted that code from a YouTube video on the subject. I'm hoping there is a simple line or two of code that I can add to the above to tell Outlook to open an new message in HTML text format. Can someone help?
 
use Outlook Automation instead of Docmd.SendObject.
 
To SLIGHTLY expand what arnelgp said, using DoCmd.SendObject uses a minimalist approach, a "lowest common denominator" approach, to mail. That is because it has to work with whatever mail client you have. Not everyone uses Outlook.

If you specifically want to control Outlook in detail, you have to read up on "Application Objects" and then create an Outlook Application Object, for which you have highly detailed control over how you build and display your messages. A little bit of a learning curve is involved, but it is not an impossible thing to learn.
 
To SLIGHTLY expand what arnelgp said, using DoCmd.SendObject uses a minimalist approach, a "lowest common denominator" approach, to mail. That is because it has to work with whatever mail client you have. Not everyone uses Outlook.

If you specifically want to control Outlook in detail, you have to read up on "Application Objects" and then create an Outlook Application Object, for which you have highly detailed control over how you build and display your messages. A little bit of a learning curve is involved, but it is not an impossible thing to learn.

A little bit of research later and I've got Access opening Outlook in HTML format using Application Objects. I'm working on how to attach a report (i.e., tax receipt). I think I have a bead on how to write the VBA code for that. I'll reach out if I run into something I can't manage.

In the meantime, there are a couple of wrinkles I need help ironing out. The first one I don't know that there is a solution. I have set the default font in Outlook to Times New Roman 12 pt. With the new code, Outlook changes it to Aptos 12 pt, which is the default font I believe. I read an article that says you can't program Access to change the font in Outlook. Is that correct? If it is possible, how do I write the code for that or is there a workaround in Outlook?

Wrinkle #2. I have Access programmed to use the donor(s) first name and spouse's name (where applicable) in the greeting (see code below). However, the cursor positions itself at the left margin in front of the greeting. How do I get it to move down a couple of lines? I tried putting in a couple of HTML paragraph markings (& "<P><P>") at the end of Msg, but that didn't work

Dim Msg As String

Msg = Forms!frmDonorDonation!FirstName & " and " & Forms!frmDonorDonation!Spouse & "

Dim O As Outlook.Application
Dim M As Outlook.MailItem

Set O = New Outlook.Application
Set M = O.CreateItem(olMailItem)

With M
.BodyFormat = olFormatHTML
.HTMLBody = Msg
.To = Forms!frmDonorDonation!EmailAddress
.BCC = "bwccr1955@gmail.com"
.Subject = "Official Tax Receipt Attached"
.Display

End With

Set O = Nothing
Set M = Nothing
 
you can change the default font in Outlook, itself:
outlook.png
 
You could also use a Template for your message? and even have placeholders, which you replace with data?
 
It might be easier to create an actual Access report and then send the report as a .pdf attachment rather than trying to build the HTML on the fly. Otherwise, I would use @Gasman 's template suggestion.
 

Users who are viewing this thread

Back
Top Bottom