supermaestro
Programmer
Hi. Can anybody who is an email expert see what is wrong with the following? I've put debugging code in this and know that it is going through the loop correctly and getting the email address from the query. However, when it has completed I check my mail boxes and nothing is being sent to them. Any ideas?
Private Sub mail_Click()
On Error Resume Next
Dim rs As New ADODB.Recordset
Dim sqlQuery As String
Dim strEMail As String
Dim strClient As String
Dim strMessage As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Set objOutlook = CreateObject("Outlook.application"
Set objEmail = objOutlook.CreateItem(olMailItem)
'set recordset to your query
sqlQuery = "SELECT * FROM contacts WHERE contacts.[Account Type]='" & [Forms]![General Email]![Account Type] & "';"
Set rs = CurrentProject.Connection.Execute(sqlQuery)
Do While Not rs.EOF
strEMail = rs.Fields("Email"
strMessage = Me!message
strSubject = Me!subject
With objEmail
.To = strEMail 'client email address taken from the query
.subject = strSubject 'email subject
.Body = strMessage 'uses normal plain text. This is your personalized
'message that was created above
.Send 'sends email
End With
'move to the next record in the query
rs.MoveNext
Loop
MsgBox "All Emails Have Been Sent"
rs.Close
Set objEmail = Nothing
objOutlook.Quit
Set objOutlook = Nothing
End Sub
Private Sub mail_Click()
On Error Resume Next
Dim rs As New ADODB.Recordset
Dim sqlQuery As String
Dim strEMail As String
Dim strClient As String
Dim strMessage As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Set objOutlook = CreateObject("Outlook.application"
Set objEmail = objOutlook.CreateItem(olMailItem)
'set recordset to your query
sqlQuery = "SELECT * FROM contacts WHERE contacts.[Account Type]='" & [Forms]![General Email]![Account Type] & "';"
Set rs = CurrentProject.Connection.Execute(sqlQuery)
Do While Not rs.EOF
strEMail = rs.Fields("Email"
strMessage = Me!message
strSubject = Me!subject
With objEmail
.To = strEMail 'client email address taken from the query
.subject = strSubject 'email subject
.Body = strMessage 'uses normal plain text. This is your personalized
'message that was created above
.Send 'sends email
End With
'move to the next record in the query
rs.MoveNext
Loop
MsgBox "All Emails Have Been Sent"
rs.Close
Set objEmail = Nothing
objOutlook.Quit
Set objOutlook = Nothing
End Sub