G
Gus
Hurray, the code is working. Well, for the most part, but it is really close,
I can feel it. I no longer get any error messages, but when the code runs a
parameter window pops up asking for RACA_Agr_Num, If I hit Okay the code runs
and formats an email.
If there are more than one Reminders for a person it continues to bring up
the parameter box and format an email with the report for each reminder for
that person.
For example I currently have two reminders, and when I ranned the code it
formatted two emails for with the same report. How could I have the code
format just one email even if I have multiple reminders.
As to the parameter box, if I hit Cancel (ERROR 25010 LoopAgmtsSendEmail)
message pops up and it read (The SendObject action was canceled).
Then it points to this.
---> Stop: Resume
Resume Exit_proc
Private Sub cmdSendEmail_Click()
Dim strSQL As String
strSQL = "SELECT tblUSers.User_FName AS UserName " _
& ", tblAgreements.Agr_Num " _
& ", tblAgreements.Action_Item " _
& ", tblAgreements.Date_Action_Reminder " _
& ", tblAgreements.Date_Action_Required " _
& ", tblUSers.Team " _
& ", tblUSers.Email " _
& " FROM tblUSers " _
& " INNER JOIN tblAgreements" _
& " ON tblUSers.User_ID = tblAgreements.UserID" _
& " WHERE (((tblAgreements.Date_Action_Reminder)=Date()))" _
LoopAgmtsSendEmail strSQL
End Sub
Option Compare Database
Sub LoopAgmtsSendEmail( _
pSQL As String)
'Crystal
'strive4peace2007 at yahoo dot com
'NEED reference to
'Microsoft DAO Library
'PARAMETERS
'pSQL -- defines the recordset to open
' -- this can be a tablename, queryname, or SQL statement..."
'dimension variables
Dim r As DAO.Recordset
Dim i As Integer
'Set up error handler
On Error GoTo Err_proc
'comment or take this line out after procedure is tested
Debug.Print pSQL
'open the Recordset
Set r = CurrentDb.OpenRecordset(pSQL, dbOpenSnapshot)
'loop through the Recordset until the end
i = 0
Do While Not r.EOF
Docmd.SendObject _
acReport _
, "Daily Reminders All Teams Report" _
, acFormatHTML _
, r!email _
, _
, _
, "Your Reminder for " & Format(Date, "ddd m-d-yy"), "Good
Morning, your report is attached" _
, True _
i = i + 1
r.MoveNext
Loop
MsgBox i & " emails were sent", , "Done"
Exit_proc:
On Error Resume Next
'close the recordset
r.Close
'release object variables
Set r = Nothing
Exit Sub
Err_proc:
MsgBox Err.Description _
, , "ERROR " & Err.Number _
& " LoopAgmtsSendEmail"
'press F8 to step through code and see where problem is
'comment next line after routine is debugged
Stop: Resume
Resume Exit_proc
End Sub
Thanks Crystal. I am excited to see I have learned somethings with your help.
I can feel it. I no longer get any error messages, but when the code runs a
parameter window pops up asking for RACA_Agr_Num, If I hit Okay the code runs
and formats an email.
If there are more than one Reminders for a person it continues to bring up
the parameter box and format an email with the report for each reminder for
that person.
For example I currently have two reminders, and when I ranned the code it
formatted two emails for with the same report. How could I have the code
format just one email even if I have multiple reminders.
As to the parameter box, if I hit Cancel (ERROR 25010 LoopAgmtsSendEmail)
message pops up and it read (The SendObject action was canceled).
Then it points to this.
---> Stop: Resume
Resume Exit_proc
Private Sub cmdSendEmail_Click()
Dim strSQL As String
strSQL = "SELECT tblUSers.User_FName AS UserName " _
& ", tblAgreements.Agr_Num " _
& ", tblAgreements.Action_Item " _
& ", tblAgreements.Date_Action_Reminder " _
& ", tblAgreements.Date_Action_Required " _
& ", tblUSers.Team " _
& ", tblUSers.Email " _
& " FROM tblUSers " _
& " INNER JOIN tblAgreements" _
& " ON tblUSers.User_ID = tblAgreements.UserID" _
& " WHERE (((tblAgreements.Date_Action_Reminder)=Date()))" _
LoopAgmtsSendEmail strSQL
End Sub
Option Compare Database
Sub LoopAgmtsSendEmail( _
pSQL As String)
'Crystal
'strive4peace2007 at yahoo dot com
'NEED reference to
'Microsoft DAO Library
'PARAMETERS
'pSQL -- defines the recordset to open
' -- this can be a tablename, queryname, or SQL statement..."
'dimension variables
Dim r As DAO.Recordset
Dim i As Integer
'Set up error handler
On Error GoTo Err_proc
'comment or take this line out after procedure is tested
Debug.Print pSQL
'open the Recordset
Set r = CurrentDb.OpenRecordset(pSQL, dbOpenSnapshot)
'loop through the Recordset until the end
i = 0
Do While Not r.EOF
Docmd.SendObject _
acReport _
, "Daily Reminders All Teams Report" _
, acFormatHTML _
, r!email _
, _
, _
, "Your Reminder for " & Format(Date, "ddd m-d-yy"), "Good
Morning, your report is attached" _
, True _
i = i + 1
r.MoveNext
Loop
MsgBox i & " emails were sent", , "Done"
Exit_proc:
On Error Resume Next
'close the recordset
r.Close
'release object variables
Set r = Nothing
Exit Sub
Err_proc:
MsgBox Err.Description _
, , "ERROR " & Err.Number _
& " LoopAgmtsSendEmail"
'press F8 to step through code and see where problem is
'comment next line after routine is debugged
Stop: Resume
Resume Exit_proc
End Sub
Thanks Crystal. I am excited to see I have learned somethings with your help.