Hi everybody,
Hope you are great. I have a question about something I want to know if can be done or not. I have an access database that sends one e-mail to each individual in a table, that works fine. Now I would like to send an e-mail to the leaders of these individuals, however, some leaders have more than individual under their scope so to avoid sending several emails, I would like to know if there is any way I can send one e-mail to the person with the names of the individuals he leads in the body of the e-mail. Is this possible?
This is the code I have that sends emails to the individuals:
Hope you are great. I have a question about something I want to know if can be done or not. I have an access database that sends one e-mail to each individual in a table, that works fine. Now I would like to send an e-mail to the leaders of these individuals, however, some leaders have more than individual under their scope so to avoid sending several emails, I would like to know if there is any way I can send one e-mail to the person with the names of the individuals he leads in the body of the e-mail. Is this possible?
This is the code I have that sends emails to the individuals:
Code:
Private Sub Command2_Click()
Dim MyDB As Database
Dim MyRS As Recordset
Dim MyForm As Form
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim TheAddress As String
Dim objOutlookAttach As Outlook.Attachment
patha = "C:\Users\lucila.planich\Documents\WBSE.jpg"
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("WBS - 2nd communication")
MyRS.MoveFirst
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Do Until MyRS.EOF
' Create the e-mail message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
TheAddress = MyRS![Enterprise]
With objOutlookMsg
' Add the To recipients to the e-mail message.
Set objOutlookRecip = .Recipients.Add(TheAddress)
objOutlookRecip.Type = olBCC
' Set the Subject, the Body, and the Importance of the e-mail message.
.To = MyRS![Enterprise]
.Subject = "CORRIGENDUM: URGENT ACTION REQUIRED"
.HTMLBody = "<html><body><font face=calibri> Dear Assignee,</font></body></html>" & vbNewLine & _
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
'If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(patha)
'End If
' Resolve the name of each Recipient.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With
MyRS.MoveNext
Loop
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub