Solved

Format Font In Access 2010 VBA

Posted on 2014-04-17
5
820 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
  • 3
5 Comments
 
LVL 34

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

The problems with reply email signatures

Do you wish that you could place an email signature under a reply? Well, unfortunately, you can't. That great Exchange/Office 365 signature you've created will just appear at the bottom of an email chain. What a pain! Is there really no way to solve this? Well, there might be...

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

743 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

15 Experts available now in Live!

Get 1:1 Help Now