By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,083 Members | 1,957 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,083 IT Pros & Developers. It's quick & easy.

One outlook email not displaying HTML formatted message?

P: 2
XP SP2, access and outlook 2003

I have a form with 3 command buttons on that when one is pressed it opens up a html email for the user to send. Two of the emails work fine and open with the full colour and size formatted text but one of them just shows the html code in the body with no formatting.

The vba code for the command button is as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdUpdateEmail_Click() 
  2. Dim HTMLReminderEmail As String 
  3. Dim Subject As String 
  4. Dim objOutlook As Outlook.Application 
  5. Dim objOutlookMsg As Outlook.MailItem 
  6. Dim RefNo As Integer 
  7.  
  8. Set conn = New ADODB.Connection
  9.  ' Specify the OLE DB provider. 
  10. conn.Provider = "sqloledb" 
  11.  
  12. ' Set SQLOLEDB connection properties. 
  13. conn.Properties("Data Source").Value = "PPE-DB2" 
  14. conn.Properties("Initial Catalog").Value = "Live_Service" 
  15.  
  16. 'Windows NT authentication. 
  17. conn.Properties("Integrated Security").Value = "SSPI" 
  18.  
  19. ' Open the database. 
  20. conn.Open 
  21.  
  22. RefNo = Me.txtRefNo 
  23. Set rs1M = New ADODB.Recordset 
  24. rs1M.Open "Select * from _1MIncidents WHERE [RefNo] = " & RefNo, conn, adOpenDynamic, adLockOptimistic 
  25. 'Create the application 
  26. Set objOutlook = CreateObject("Outlook.Application") 
  27. Create the mail item 
  28. Set objOutlookMsg = objOutlook.CreateItem(olMailItem) 
  29.  
  30. 'HTMLReminderEmail = "<HTML><Font Face = " & Chr(34) & "Arial" & Chr(34) & "><Font color = " & Chr(34) & "Blue" & Chr(34) & "><Font Size = " & Chr(34) & "3" & Chr(34) & ">All,<br><br>The problem has been identified,</font color></font size><font color = " & Chr(34) & "Red" & Chr(34) & "><Font Size = " & Chr(34) & "4" & Chr(34) & ">Please do not attempt to use " & rs1M![systemArea] & " until further notice.<br><br></font color></font size><Font color = " & Chr(34) & "Blue" & Chr(34) & "><Font Size = " & Chr(34) & "3" & Chr(34) & ">The Business Systems Team are working to return normal service ASAP.</Font Size></Font Color></Font></HTML>" 'HTMLReminderEmail = "<HTML><body><font face = " & Chr(34) & "Arial" & Chr(34) & "><font size = " & Chr(34) & "2" & Chr(34) & "><font color = " & Chr(34) & "Blue" & Chr(34) & ">All, <br><br>The Problem has been identified, </font color></font size><font size = " & Chr(34) & "3" & Chr(34) & "><font color = " & Chr(34) & "Red" & Chr(34) & ">Please do not attempt to use " & rs1M![systemArea] & " until further notice.<br><br></font color></font size><font size = " & Chr(34) & "2" & Chr(34) & "><font color = " & Chr(34) & "Blue" & Chr(34) & ">The Business Systems Team are working to return normal service ASAP.</font color></font size></font face></font></body></HTML>" 'MsgBox HTMLReminderEmail HTMLReminderEmail = "<HTML><Font Face = " & Chr(34) & "Arial" & Chr(34) & "><Font color = " & Chr(34) & "Blue" & Chr(34) & "><Font Size = " & Chr(34) & "3" & Chr(34) & ">All,<br><br>The problem has been identified,<font color = " & Chr(34) & "Red" & Chr(34) & "><Font Size = " & Chr(34) & "4" & Chr(34) & ">Please do not attempt to use " & rs1M![systemArea] & " until further notice.<br><br></font color></font size>The Business Systems Team are working to return normal service ASAP.</Font Size></Font Color></Font></HTML>" 
  31.  
  32. Subject = rs1M![systemArea] & " Error" 
  33.  
  34. With objOutlookMsg 
  35.     .To = "Matthew.Bradshaw@prepol.com" 
  36.     .Subject = Subject 
  37.     .body = HTMLReminderEmail 
  38.     .BodyFormat = olFormatHTML 
  39.     .Display 
  40. End With rs1M![LastEmailed] = DateTime.Now rs1M.Update
The html code produced is

"<HTML><Font Face = "Arial"><Font color = "Blue"><Font Size = "3">All,<br><br>The problem has been identified,<font color = "Red"><Font Size = "4">Please do not attempt to use Syteline until further notice.<br><br></font color></font size>The Business Systems Team are working to return normal service ASAP.</Font Size></Font Color></Font></HTML>"

When the html is put in a notepad file and saved as a html document it displays correctly, but for some reason outlook is not picking up the html for this email.

Thanks in advance Matt
Sep 4 '08 #1
Share this Question
Share on Google+
1 Reply


P: 2
Never mind just realised in the objoutlookmessage with should e .htmlbody not .body.

Spent about 2 hours trying to get this to work.
Sep 4 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.