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
- Private Sub cmdUpdateEmail_Click()
- Dim HTMLReminderEmail As String
- Dim Subject As String
- Dim objOutlook As Outlook.Application
- Dim objOutlookMsg As Outlook.MailItem
- Dim RefNo As Integer
- Set conn = New ADODB.Connection
- ' Specify the OLE DB provider.
- conn.Provider = "sqloledb"
- ' Set SQLOLEDB connection properties.
- conn.Properties("Data Source").Value = "PPE-DB2"
- conn.Properties("Initial Catalog").Value = "Live_Service"
- 'Windows NT authentication.
- conn.Properties("Integrated Security").Value = "SSPI"
- ' Open the database.
- conn.Open
- RefNo = Me.txtRefNo
- Set rs1M = New ADODB.Recordset
- rs1M.Open "Select * from _1MIncidents WHERE [RefNo] = " & RefNo, conn, adOpenDynamic, adLockOptimistic
- 'Create the application
- Set objOutlook = CreateObject("Outlook.Application")
- Create the mail item
- Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
- '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>"
- Subject = rs1M![systemArea] & " Error"
- With objOutlookMsg
- .To = "Matthew.Bradshaw@prepol.com"
- .Subject = Subject
- .body = HTMLReminderEmail
- .BodyFormat = olFormatHTML
- .Display
- End With rs1M![LastEmailed] = DateTime.Now rs1M.Update
"<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