• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 920
  • Last Modified:

Format Font In Access 2010 VBA

I am struggling with changing the font, adding a line and making some statements bold in the msgbody of the following code.  Can you help or lead me to a resource?

Thanks in advance,

Private Sub cmdEMAIL_NA_Click()
On Error GoTo Err_cmdEMAIL_NA_Click

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim appOutlook As Outlook.Application
Dim msg As Outlook.MailItem
Dim strEmail As String
Dim msgbody As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblEMAIL_TMP")
Set appOutlook = GetObject(, "Outlook.Application")
  strEmail = Nz(rst![DC1EMAIL])
       'Create email
         Set msg = appOutlook.CreateItem(olMailItem)
         msg.To = strEmail
         msg.Subject = "Nissan Claims Audit Survey "
         msgbody = "Dear" & " " & rst![DC1TL] & " " & [DC1LN] & "," & vbCrLf
         msgbody = msgbody & " " & vbCrLf
         msgbody = msgbody & "We would greatly appreciate you taking a few minutes to complete a short survey regarding the Operational Review and Training Visit (ORTV) that recently took place with your dealership. " & vbCrLf
         msgbody = msgbody & "Your candor and feedback will help us improve our processes. " & vbCrLf
         msgbody = msgbody & " " & vbCrLf
         msgbody = msgbody & "Please note that your responses are anonymous, unless you choose otherwise.  Thank you in advance for your time. " & vbCrLf
         msgbody = msgbody & " " & vbCrLf
         msgbody = msgbody & "Please click here to begin the survey:  https://www.surveymonkey.com/s/NissanClaimsAUDITFY14 "
         msg.Body = msgbody
   Set rst = Nothing
   Set appOutlook = Nothing
   Exit Sub

   'Outlook is not running; open Outlook with CreateObject
   If err.Number = 429 Then
      Set appOutlook = CreateObject("Outlook.Application")
      Resume Next
      MsgBox "Error No: " & err.Number _
         & " in EMailAllContacts procedure" _
         & "; Description: " & err.DESCRIPTION
      Resume ErrorHandlerExit
   End If

    DoCmd.RunCommand acCmdAutoDial

    Exit Sub

    Resume Next
    Resume Exit_cmdEMAIL_NA_Click
End Sub
  • 3
3 Solutions
Usually you want your body text to be plain.  Many people have their email readers set to not allow Rich Text so your formatting would get lost anyway.  To apply formatting, you would need to set the body to Rich Text (I don't know how to do it) and you would need to embed tags in the text to set the formatting.  I don't know whether the body needs to be RTF or HTML.  Both use tags but they would be different.  You can figure out either technique by using Word.

Create a document that has the text formatted as you want.  Save the document first as RTF and then as HTML.  Then open Notepad and with Notepad, open the RTF document to determine the necessary tags for that schema and then open the HTML document to see the HTML tags.  Both RTF and HTML are text formats which is why Notepad can open them but because notepad doesn't render the formatting, you are able to view the actual codes.
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You can set the .HTMLBody property of your message. Instead of:

msg.Body = msgbody


msg.BodyFormat = olFormatHTML
msg.HTMLBody = msgbody

You can use either HTML or RTF tags, but obviously you'd need to change the BodyFormat argument to reflect your choice. If you just need the basics, like Bold or Underline, then HTML is fine. If you're trying to set specific Fonts, be aware that the font must exist on the target machine, or the email reader will default to a different one.

Of the two formats, RTF is the trickiest. Unless you really, really need it I'd stick with HTML.

Whatever format you choose, be sure your "document" (i.e. the Body) is well formed. For example, if you're using the HTML format, make sure you have <HTML></HTML> and <Body></Body> tag wraps.

Finally, I've been using the vbMAPI product from www.everythingaccess.com for several years, and have found it to be an invaluable tool. It's very easy to use and deploy (there are no 3rd party libraries, everything is included directly in the application), and it makes working with Outlook a breeze. Note I have no affiliation with the product other than being a satisfied user.
castlerjSenior AnalystAuthor Commented:
Thanks for the response...I'll do some more testing and see what I can do...
castlerjSenior AnalystAuthor Commented:
Closing question
castlerjSenior AnalystAuthor Commented:
I tried both and I still can not get things to work. I will have to keep trying and reading up on the subject. Thanks for the advice!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

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