This post is related to archived thread702-396121.
I used the code provided in the thread above to automatically generate e-mail messages to employees when they have an overdue task. The code is tied to a command button on my form.
What I would like to do is have all of the e-mail messages generated for all records in the form when I click the command button instead of having to go to each record and click on the command button.
The number of records varies depending on the number of overdue records that day.
Here is my code:
=======================================================
Private Sub cmdPreviewEmail_Click()
Dim strEmail, strBody, strSubject, strFrom As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
'**creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
'*****************************************
'*create string with email address
strFrom = "GMB-EITSS-Work-Engagement"
strEmail = CCAddress
strSubject = SUBJECT
strBody = MainText
'***creates and previews email
With objEmail
.SentOnBehalfOfName = strFrom
.To = strEmail
.SUBJECT = strSubject
.Body = strBody
.Preview
End With
Set objEmail = Nothing
Exit Sub
End Sub
=======================================================
I used the code provided in the thread above to automatically generate e-mail messages to employees when they have an overdue task. The code is tied to a command button on my form.
What I would like to do is have all of the e-mail messages generated for all records in the form when I click the command button instead of having to go to each record and click on the command button.
The number of records varies depending on the number of overdue records that day.
Here is my code:
=======================================================
Private Sub cmdPreviewEmail_Click()
Dim strEmail, strBody, strSubject, strFrom As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
'**creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
'*****************************************
'*create string with email address
strFrom = "GMB-EITSS-Work-Engagement"
strEmail = CCAddress
strSubject = SUBJECT
strBody = MainText
'***creates and previews email
With objEmail
.SentOnBehalfOfName = strFrom
.To = strEmail
.SUBJECT = strSubject
.Body = strBody
.Preview
End With
Set objEmail = Nothing
Exit Sub
End Sub
=======================================================