Results 1 to 7 of 7
  1. #1
    Corey is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    11

    Email outmation, proper use of .HTMLBody (tags)?

    Can someone direct me how to properly get my email body to format correctly? I am obviously misusing the .HTMLbody/tags incorrectly. The email generates with the attachments as expected, but the email body message is just runon, with no breaks/formatting of any kind.



    Code:
    Private Sub Command29_Click()
    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    DoCmd.OutputTo acOutputReport, "WelcomeLetter_rpt", acFormatPDF, "\\C:\Access\Ob\Welcome Letter_" & [First Name] & Space(1) & [Last Name] & ".pdf"
    With MailOutLook
       .BodyFormat = olFormatHTML
      .To = [Forms]![CustomerUsers_Send_frm]![Email]
       .CC = DLookup("[CC DL]", "Customers", "[Customer]=[Forms]![CustomerUsers_Send_frm]![Customer]") & ";" & DLookup("[MgrEmail]", "Customers", "[Customer]=[Forms]![CustomerUsers_Send_frm]![Customer]")
       .Subject = "Welcome New Company ABC Portal User"
      .HTMLBody = "Hello" & Space(1) & [Forms]![CustomerUsers_Send_frm]![First Name] & "," & Chr(10) & vbCrLf _
            & DLookup("[EmailMessage]", "WelcomeEmail") & Chr(10) & vbCrLf _
            & DLookup("[TollFreeName]", "WelcomeEmail", "[Customer]=[Forms]![CustomerUsers_Send_frm]![Customer]") & Space(1) & DLookup("[TollFreeNum]", "WelcomeEmail") & vbCrLf _
            & DLookup("[DirectNumName]", "WelcomeEmail", "[Customer]=[Forms]![CustomerUsers_Send_frm]![Customer]") & Space(1) & DLookup("[DirectNum]", "WelcomeEmail", "[Customer]=[Forms]![CustomerUsers_Send_frm]![Customer]") & Chr(10) & vbCrLf _
            & "Thank you," & Chr(10) & vbCrLf _
            & "Company Service Management" & vbCrLf _
            & "Company ABC" & Chr(10) & vbCrLf _
            & DLookup("[Tag]", "WelcomeEmail")
       .Attachments.Add ("C:/Access/Ob/Welcome Letter_" & [First Name] & Space(1) & [Last Name] & ".pdf")
       .Attachments.Add ("C:/Access/Ob/Guide.pdf")
       .DeleteAfterSubmit = False
       .Display
      End With
       
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    With HTML, you have to use <br> inside the string instead of vbCrLf outside of it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Corey is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    11
    Can you clarify "inside"? I get removing vbCrLf outside the string...but where does <br> get applied inside?

  4. #4
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,368
    Construct a string, then add the result to the .body. It is easier to write, see the result and control the output if it doesn't look right in the immediate window. For example, assuming you have other variables declared as strings:

    svBody = "<HTML> <HEAD><font ...> Hello " & svTo & " ; <br><br>"
    svBody = svBody & "blah, blah, blah &nbsp;&nbsp"
    svBody = svBody & "</font></HEAD></HTML>"
    I'm a bit rusty with my html, so maybe a boo-boo in that. You might have to add the DOCTYPE declaration at the very beginning to control font formatting.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Quote Originally Posted by Corey View Post
    Can you clarify "inside"? I get removing vbCrLf outside the string...but where does <br> get applied inside?
    Like

    .HTMLBody = "Hello" & Space(1) & [Forms]![CustomerUsers_Send_frm]![First Name] & ", <br>"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Corey is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    11
    Thank you again!

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. htmlbody editing
    By trevor40 in forum Programming
    Replies: 2
    Last Post: 02-13-2014, 04:38 PM
  2. email notification with proper format
    By joshynaresh in forum Access
    Replies: 5
    Last Post: 02-04-2014, 10:17 AM
  3. Tags to filter
    By SwaziMan in forum Access
    Replies: 1
    Last Post: 07-04-2011, 11:29 AM
  4. Indenting Using htmlbody
    By graviz in forum Programming
    Replies: 1
    Last Post: 12-18-2009, 05:56 PM
  5. Email with proper page orientation of Report
    By Robert M in forum Programming
    Replies: 1
    Last Post: 08-17-2009, 10:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums