I'm having a bit of difficulty with this code. In a simpler form it works just fine except line breaks in the contacts section of the body were not being shown when recieved by recipients.
In RTF format this is not the case; however, now the code no longer loops through the recordset. It only sends to the first record.
Help! I need it to loop through the entire recordset!!!
In RTF format this is not the case; however, now the code no longer loops through the recordset. It only sends to the first record.
Help! I need it to loop through the entire recordset!!!
Code:
Function SponsorApproval1()
On Error GoTo SA_Error
Dim ESA As String
Dim Title As String
Dim Message As Integer
ESA = "You are about to send emails to all Executive Sponsors with outstanding approvals." & (Chr(13)) & (Chr(13)) & "Do you want to continue?"
Title = "Executive Sponsor Approval"
Message = MsgBox(ESA, vbYesNo, Title)
Dim EmlTo As String
Dim EmlSubject As String
Dim EmlMessage As String
Dim dbs As Database
Dim rst As DAO.Recordset
Dim fmt As String
Dim bodyText As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SponsorApproval")
'the F in rst(F) refers to the field in the query holding the email addresses
With rst
If .RecordCount <> 0 Then
If Message = vbNo Then
Exit Function
Else
Do While Not rst.EOF
EmlTo = rst("Email")
EmlSubject = "The '" & rst("Project Name") & "' report approval is past due."
EmlMessage = rst("First") & "," & vbNewLine & vbNewLine & "Please review/approve the status report in the Strategic Platform Dashboard database. If you have any issues, please contact your Project Manager (" & rst("Manager 1") & " - x" & rst("phone") & ") or someone from the listing below." & vbNewLine & vbNewLine & "Thank you." & vbNewLine & vbNewLine & "Strategic Development Contacts:" & vbNewLine & rst("VP") & vbNewLine & rst("dba") & vbNewLine & rst("PC") & vbNewLine & rst("AC")
With objEmail
.To = EmlTo
.Subject = EmlSubject
.Body = EmlMessage
.BodyFormat = olFormatRichText
.Display
End With
.MoveNext
Loop
End If
End If
End With
SA_Error:
Exit Function
End Function