Solved

Format Font In Access 2010 VBA

Posted on 2014-04-17
5
867 Views
Last Modified: 2014-05-06
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
         msg.Display
         
ErrorHandlerExit:
   rst.Close
   Set rst = Nothing
   Set appOutlook = Nothing
   Exit Sub

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

    Screen.PreviousControl.SetFocus
    DoCmd.RunCommand acCmdAutoDial

Exit_cmdEMAIL_NA_Click:
    Exit Sub

Err_cmdEMAIL_NA_Click:
    Resume Next
    Resume Exit_cmdEMAIL_NA_Click
End Sub
0
Comment
Question by:castlerj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 37

Assisted Solution

by:PatHartman
PatHartman earned 250 total points
ID: 40007879
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.
0
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 40008771
You can set the .HTMLBody property of your message. Instead of:

msg.Body = msgbody

Use:

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.
0
 

Accepted Solution

by:
castlerj earned 0 total points
ID: 40012835
Thanks for the response...I'll do some more testing and see what I can do...
0
 

Author Comment

by:castlerj
ID: 40035681
Closing question
0
 

Author Closing Comment

by:castlerj
ID: 40043929
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!
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

734 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