BennyLinton
Registered User.
- Local time
- Today, 05:37
- Joined
- Feb 21, 2014
- Messages
- 263
I have a an Automated Email from List that is working great, except for two problems. It pulls from a table called tblContacts with three fields: Email (Y/N), FirstName, and fldEmailAddresses:
1: When the recipient receives the email it list all others that received the same email
2: I need the body of the email accept a variable for their FirstName after the hardcoded "Dear
1: When the recipient receives the email it list all others that received the same email
2: I need the body of the email accept a variable for their FirstName after the hardcoded "Dear
Code:
Dim rs As Recordset
Dim s As String, listOfMails As String
On Error Resume Next
Set oApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oApp = CreateObject("Outlook.Application")
Started = True
End If
Set oItem = oApp.CreateItem(olMailItem)
With oItem
s = "SELECT tblcontacts.fldEmailAddress" & _
" FROM tblcontacts " & _
" WHERE (((tblcontacts.Email)='Y'));"
Set rs = CurrentDb.OpenRecordset(s)
listOfMails = ""
While Not rs.EOF
listOfMails = listOfMails & rs(0) & ";"
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
.To = listOfMails
.Subject = "Test"
.Body = "This is a system-generated e-mail, please do not reply. For support please refer to:" & vbNewLine & _
"Dear it has come to our attention that you have" & vbNewLine & _
"Should you have another further inquiries, please do not hesitate to contact us" & vbNewLine & _
" " & vbNewLine & _
"Test"
.Send
End With
Set oItem = Nothing
If Started Then
oApp.Quit
End If
MsgBox "An Automatic Email has been sent.", vbOKOnly
End Sub