Keith Sparkes
Registered User.
- Local time
- Today, 14:29
- Joined
- Jan 27, 2004
- Messages
- 10
I am trying to send emails using CDO to different email recipients based on fields in a simple table called tblEmailRecipients.
There are currently 2 records in the table.
When I run my code, 2 emails are sent but the subject and text body are the same as the first record in my table. What I need to be able to do is to send to the number of records in the table with different subject. I have tried everything that I can think of and going round in circles with this.
My code is currently as follows:
(APOLOGIES FOR REMOVING THE CDO SCHEMAS AS MY POST DOESNT SEEM TO LIKE THESE SO HAVE REPLACED THE HTTP LINKS)
Please can anyone help me?
Many thanks for taking the time to read my post and any possible solutions are greatly appreicated.
There are currently 2 records in the table.
When I run my code, 2 emails are sent but the subject and text body are the same as the first record in my table. What I need to be able to do is to send to the number of records in the table with different subject. I have tried everything that I can think of and going round in circles with this.
My code is currently as follows:
Code:
Public Sub Email()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblEmailRecipients")
Set objMessage = CreateObject("CDO.Message")
Overdue = DLookup("Overdue", "tblEmailRecipients", "")
Forename = DLookup("Forename", "tblEmailRecipients", "")
Surname = DLookup("Surname", "tblEmailRecipients", "")
Do Until rs.EOF
strEmail = rs!EmailAddress
strSubject = "** Alert **" & "-" & Overdue & "-" & Surname & "," & Forename
strTextBody = "Please Check your records as some are overdue."
objMessage.To = strEmail
objMessage.From = "emailaddress"
objMessage.Subject = strSubject
objMessage.TextBody = strTextBody
objMessage.Configuration.Fields.Item _
("<MS CDO SCHEMA>") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("<MS CDO SCHEMA>") = "SMTPSERVER"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("<MS CDO SCHEMA>") = 25
objMessage.Configuration.Fields.Update
objMessage.Send
rs.MoveNext
Loop
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
(APOLOGIES FOR REMOVING THE CDO SCHEMAS AS MY POST DOESNT SEEM TO LIKE THESE SO HAVE REPLACED THE HTTP LINKS)
Please can anyone help me?
Many thanks for taking the time to read my post and any possible solutions are greatly appreicated.