Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to set font from MS Access VBA to outlook email

Posted on 2012-09-05
9
Medium Priority
?
3,090 Views
Last Modified: 2012-09-05
I have some simple code that sends an email from MS Access VBA.  It populates the Email Address, Subject and body.

Part of The body is RTF that is stored in memo field and looks great on the email

Problem is I need to poplulate part of the RTF with a Table from a recordset in the access database and have it ligned up properly on the RTF.

I originally thought creating a table in RTF would solve this issue, but NO too difficult, now I figured out if I just could use a MONOSPACED font that would be  great.  

Any suggestion on how I can change the FONT of the outgoing email from withint the VBA that creates the email?

Or other Suggestions on how to solve this issue?

Thanks,
0
Comment
Question by:Rog D
  • 5
  • 2
  • 2
9 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38368392
Lets clarify a few things:
What version of Access?
Are you using *True* RTF, or Access 2007/2010 RTF, which is really HTML.

To set the font in HTML just use something like this:
<font face="Arial">This text is in Arial Font</font>
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38368400
<I have some simple code that sends an email from MS Access VBA. >
Then why not post this code to provide more clarity?
0
 
LVL 8

Author Comment

by:Rog D
ID: 38368450
I am using Access 2010 and Outlook 2010....

Dim rs As Recordset
    Dim OutApp As Outlook.Application
    Dim outAtt As Outlook.Attachment
   
    Dim OutMail As Outlook.MailItem
    Dim strbody As String

    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)

    Set rs = CurrentDb.OpenRecordset("Select * from tblSurveyEmail where [Type] = 'SoftwareAudit'")

    On Error Resume Next
    With OutMail
        .To = sEmail '"rwdavis@olin.com" '.Email
        .Subject = rs("Subject")
        .BodyFormat = olFormatRichText
        strbody = strbody & rs("Body2")
        strbody = Replace(strbody, "[FirstName]", sFirstName)
        strbody = Replace(strbody, "[SoftWareList]", sSoftwareList)
        .Body = strbody
        .ReadReceiptRequested = True
        .display   'or use .Display
    End With
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 2000 total points
ID: 38368620
Something like this works fine for me:

 Dim OutApp As Outlook.Application
    Dim outAtt As Outlook.Attachment
   
    Dim OutMail As Outlook.MailItem
    Dim strbody As String

    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)

    'Set rs = CurrentDb.OpenRecordset("Select * from tblSurveyEmail where [Type] = 'SoftwareAudit'")

    On Error Resume Next
    With OutMail
        .To = "rwdavis@olin.com"
      '  .Subject = rs("Subject")
        strbody = "This is your Body Text"
        .htmlBody = "<font face='Arial'>" & strbody & "</font>"
        .ReadReceiptRequested = True
        .Display   'or use .Display
    End With


JeffCoachman
0
 
LVL 16

Expert Comment

by:DansDadUK
ID: 38368911
Most fonts (including Arial) are proportionally-spaced.

For a fixed-pitch (mono-spaced) font, you'd need something like Courier or Letter Gothic.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38369021
DansDadUK,

Thanks, ...then in my code the OP would have to change: "Arial" to "Courier"
0
 
LVL 16

Expert Comment

by:DansDadUK
ID: 38369719
Something like that _ I'm not sure whether the commonly accepted name is Courier, or Courier New, or something else.
0
 
LVL 8

Author Closing Comment

by:Rog D
ID: 38369733
Thanks for the info.  WITH HTML this solution worked great.

The Monospaces is great also easier to lign up the text.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38369749
Rog,
Thanks but you should have given DansDadUK some points for remembering your "MONOSPACED" requirement.

You can click the Request Attention link and ask that the points be split if you like.

;-)

Jeff
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This article will help to fix the below errors for MS Exchange Server 2016 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

580 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