locked
How to change format of text in a body of a generated email in access 2013? RRS feed

  • Question

  • Hi All,

    I am trying to change the text format in the body of the generated email but without succes. Thought about using .HTMLBody = "<HTML><B>Report from today.</B></HTML>" as I want to have this text only in bold but no result.  Any suggestion what to change in the logic see command below? 

    Private Sub Command23_Click()

    Dim day As Integer

    day = Weekday(Date, vbSunday)

    Dim olApp As Outlook.Application

    Dim toMulti As String

    Dim mItem As Outlook.MailItem  ' An Outlook Mail item

    Set olApp = CreateObject("Outlook.Application")

    Set mItem = olApp.CreateItem(olMailItem)

    Dim rs  As Recordset

      With mItem

       Set rs = CurrentDb.OpenRecordset("Count names with No products contact name")

       If rs.RecordCount > 0 Then

       rs.MoveFirst

       .BodyFormat = olFormatHTML

       Do Until rs.EOF

             toMulti = toMulti & rs![email carrier manager] & ";"

            rs.MoveNext

       Loop

        Else

          MsgBox "No email address!"

        End If

        .To = toMulti

        .CC = ""

        .Subject = "Providers with No active products today date - (" & WeekdayName(day) & " - " & Date & ")"

        .Body = "Hi All," & vbCrLf & _

    vbCrLf & "Report from today." & _

    vbCrLf & "" & vbCrLf & _

    vbCrLf & "Regards," & vbCrLf & _

    vbCrLf & "John"

        .Display

        .Attachments.Add ("C:\Users\John.peacock\Documents\Template_missing products.xlsx")

    End With

        Exit Sub

    End Sub


    Anri

    Monday, April 11, 2016 11:04 AM

Answers

  • I use this in Access:

    '***********************
    '* HTML formatting
    '*
    Private Const STARTBODY = "<html><head><style type='text/css'> body { font: 11pt Calibri, Verdana, Geneva, Arial, Helvetica, sans-serif; } </style></head><body> "
    Private Const ENDBODY = "</body></htlm>"
    
    ......
    With mlItem
    ....
    
            .BodyFormat = olFormatHTML
            .Body = theMessage 
            .HTMLBody = STARTBODY & theMessage & ENDBODY  'Add HTML & CSS formatting
    
    ....
    


    Best regards, George


    Monday, April 11, 2016 11:36 AM
  • After reading the feedback I searched on ".HTMLBody", and found some good examples. So in "strbody" I placed all the text that I want to see in the generated email, after that the text will be displayed with the commands :".HTMLBody = strbody & "<br>" & .HTMLBody"

    It worked very welll

    ********************************************** 

    strbody = "Hi All,<br><br>" & _ 

                      "text line 2 you want to see <br><br>" & _

                   "text line 3 you want to see <br><br>" & _

              "text line 4 you want to see <br><br>"   "Last text line"

    .HTMLBody = strbody & "<br>" & .HTMLBody

    Excellent!!!!


    Anri

    Monday, April 11, 2016 5:51 PM

All replies

  • I use this in Access:

    '***********************
    '* HTML formatting
    '*
    Private Const STARTBODY = "<html><head><style type='text/css'> body { font: 11pt Calibri, Verdana, Geneva, Arial, Helvetica, sans-serif; } </style></head><body> "
    Private Const ENDBODY = "</body></htlm>"
    
    ......
    With mlItem
    ....
    
            .BodyFormat = olFormatHTML
            .Body = theMessage 
            .HTMLBody = STARTBODY & theMessage & ENDBODY  'Add HTML & CSS formatting
    
    ....
    


    Best regards, George


    Monday, April 11, 2016 11:36 AM
  • Hi Anri. Without seeing what you're looking at, I just want to mention viewing an email in HTML also depends on the email client. So, make sure your email client is set to display email messages in Rich Text or HTML format. Just my 2 cents...
    Monday, April 11, 2016 3:45 PM
  • After reading the feedback I searched on ".HTMLBody", and found some good examples. So in "strbody" I placed all the text that I want to see in the generated email, after that the text will be displayed with the commands :".HTMLBody = strbody & "<br>" & .HTMLBody"

    It worked very welll

    ********************************************** 

    strbody = "Hi All,<br><br>" & _ 

                      "text line 2 you want to see <br><br>" & _

                   "text line 3 you want to see <br><br>" & _

              "text line 4 you want to see <br><br>"   "Last text line"

    .HTMLBody = strbody & "<br>" & .HTMLBody

    Excellent!!!!


    Anri

    Monday, April 11, 2016 5:51 PM
  • You don't need to add .HTMLBody to itself

    Best regards, George

    Tuesday, April 12, 2016 4:24 AM