I want to be able to send a HTML formatted e-mail to several clients. The HTML Body will be the same but I would like each e-mail to be addressed using access controls.
I have put to-gether some code that I have found and added to. For testing I have 3 clients in my database and they all appear fine in my recordset query.
My Problem is that the code wants to send the same email (first client in query) 3 times. Would someone be kind enough to have a look at my code and see what I am missing (or doing wrong).
Dim olApp As Object
Dim objItem As Object
Dim strMsg As String
Dim strName As String
Dim strUni As String
Dim strSaluation As String
Dim strTo As String
Dim rsEmail As DAO.Recordset
Set rsEmail = CurrentDb.OpenRecordset("QryEMail")
strName = rsEmail.Fields("CusName").Value
strUni = rsEmail.Fields("University").Value
strSalutation = rsEmail.Fields("CusSalutation").Value
strTo = rsEmail.Fields("EMail").Value
strMsg = "<HTML><BODY> <p><span style=font-size:10.0pt;font-family:Tahoma>" & _
strName & "<br> " & _
strUni & "<br><br> " & _
"Dear" & " " & strSalutation & "," & "<br><br> " & _
"I would like to sincerely thank you etc etc </BODY></HTML>"
Do While Not rsEmail.EOF
Set olApp = CreateObject("Outlook.Application")
Set objItem = olApp.CreateItem(0)
.To = strTo
.Subject = "Example of HTML in Access"
.BodyFormat = olFormatHTML
.HTMLBody = strMsg
Set rsEmail = Nothing