Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Format Font In Access 2010 VBA

Posted on 2014-04-17
5
Medium Priority
?
891 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 40

Assisted Solution

by:PatHartman
PatHartman earned 750 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 85

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 750 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

Technology Partners: 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!

Question has a verified solution.

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
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…

926 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