platypus71
Technical User
Okay, a while back I was able to use code to send automated emails. This code works wonderfully for what we are doing. Unfortunately, we've expanded our needs and now I need a more complex email.
What I am trying to do: sqlstr2 generates a list of each person that we need to send an email to. sqlstr creates a list of the Metrics to send to said person (ShortName).
I want to then send my canned message that gives a list of the Metrics in it to each ShortName. What I came up with doesn't quite work.... Any help would be appreciated, I know I'm missing something simple.
What I am trying to do: sqlstr2 generates a list of each person that we need to send an email to. sqlstr creates a list of the Metrics to send to said person (ShortName).
I want to then send my canned message that gives a list of the Metrics in it to each ShortName. What I came up with doesn't quite work.... Any help would be appreciated, I know I'm missing something simple.
Code:
Function Reminder()
Dim X As Boolean
Dim mydb As Database
Dim rst As Recordset
Dim sqlstr As String
Dim sbj As String
Dim bod As String
Dim list As String
'Define the SQL Strings for each email below
sqlstr2 = "SELECT MetricsContactList.ShortName, MetricsContactList.[Metric Owner] FROM MetricsContactList WHERE (((MetricsContactList.Frequency) Like 'MO') AND ((MetricsContactList.Automated)<>True)) GROUP BY MetricsContactList.ShortName, MetricsContactList.[Metric Owner];"
sqlstr = "SELECT MetricsContactList.Code, MetricsContactList.Metric, MetricsContactList.ShortName FROM MetricsContactList WHERE (((MetricsContactList.Frequency) Like 'MO') AND ((MetricsContactList.Automated)<>True) AND ((MetricsContactList.ShortName) Like rst1!ShortName));"
Set mydb = CurrentDb
'This sends reminders for metrics
Set rst1 = mydb.OpenRecordset(sqlstr2)
Do While Not rst1.EOF
Set rst = mydb.OpenRecordset(sqlstr)
Do While Not rst.EOF
list = rst!Metric & list
rst.MoveNext
Loop
sbj = "REMINDER: Enter your monthly metrics"
bod = "Dear " & rst1![Metric Owner] & "," & vbCrLf & vbCrLf & "Please take a few minutes to complete your metrics entry for the Scorecard." & vbCrLf & "Your metrics are:" & rst!Metric & vbCrLf & "Thank you!"
X = SendEmail(rst1!ShortName, bod, "", sbj, "")
rst1.MoveNext
Loop
End Function