J
Jack
Hi,
I am testing the following code to send email based on criteria from a
query. If there are three records then three emails will be sent by looping
three times in the recordset of the query. However I do not want Access to
open up and I need to click send to send the email. I want the emails to be
send automatically on the click of a form button. I would appreciate any help
to resolve this. Thanks
CODE:
Dim db As DAO.Database, rs As DAO.Recordset
Dim sSQL As String
'Set environment
Set db = CurrentDb
DoCmd.SetWarnings False
'Open the controlling recordset
Set rs = db.OpenRecordset("qrySendEmailAdvice")
While Not rs.EOF
'For each record (CaseID) send an email
DoCmd.SendObject acSendNoObject, , , rs![EmailAddress], , , "Case
Closing Reminder", _
"Dear " & rs![Employee] & vbCrLf & vbCrLf & "Your case
corresponding to " & rs![CaseID] & _
vbCrLf & vbCrLf & "is five days overdue. You need to work on this
to close it"
'Update the Booking table so that emails are not duplicated
sSQL = "UPDATE tblEmployeeCase SET EmailSent=-1 where CaseID=" &
rs![CaseID]
db.Execute sSQL
'Cycle on to the next record
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
'Control recordset now closed
'Reset environment
DoCmd.SetWarnings True
I am testing the following code to send email based on criteria from a
query. If there are three records then three emails will be sent by looping
three times in the recordset of the query. However I do not want Access to
open up and I need to click send to send the email. I want the emails to be
send automatically on the click of a form button. I would appreciate any help
to resolve this. Thanks
CODE:
Dim db As DAO.Database, rs As DAO.Recordset
Dim sSQL As String
'Set environment
Set db = CurrentDb
DoCmd.SetWarnings False
'Open the controlling recordset
Set rs = db.OpenRecordset("qrySendEmailAdvice")
While Not rs.EOF
'For each record (CaseID) send an email
DoCmd.SendObject acSendNoObject, , , rs![EmailAddress], , , "Case
Closing Reminder", _
"Dear " & rs![Employee] & vbCrLf & vbCrLf & "Your case
corresponding to " & rs![CaseID] & _
vbCrLf & vbCrLf & "is five days overdue. You need to work on this
to close it"
'Update the Booking table so that emails are not duplicated
sSQL = "UPDATE tblEmployeeCase SET EmailSent=-1 where CaseID=" &
rs![CaseID]
db.Execute sSQL
'Cycle on to the next record
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
'Control recordset now closed
'Reset environment
DoCmd.SetWarnings True