adhoustonj
Member
- Local time
- Today, 08:44
- Joined
- Sep 23, 2022
- Messages
- 192
Hello,
I hope this post is in the right place. The code below is populating the bcc and to fields in my outlook message. Is it possible to only populate the bcc and leave the to field blank? Or am I approaching this wrong and should loop through and send an individual email to each email from the recordset?
I hope this post is in the right place. The code below is populating the bcc and to fields in my outlook message. Is it possible to only populate the bcc and leave the to field blank? Or am I approaching this wrong and should loop through and send an individual email to each email from the recordset?
Code:
Private Sub Command180_Click()
Dim rs As DAO.Recordset
Dim OlApp As Object
Dim OutMail As Object
Dim strEmail As String
Dim bccEmails As String
Set OlApp = CreateObject("Outlook.Application")
Set OutMail = OlApp.CreateItem(olMailItem)
Set rs = CurrentDb.OpenRecordset("SELECT DISTINCT Email FROM tblEmail")
With rs
Do Until .EOF
strEmail = !Email
' add email to BCC email list string
bccEmails = bccEmails & strEmail & ";"
With OutMail
.Recipients.Add strEmail
End With
rs.MoveNext
Loop
End With
rs.Close
Set rs = Nothing
' set BCC using string of concatenated emails
OutMail.BCC = left(bccEmails, Len(bccEmails) - 1) ' trims trailing semicolon
OutMail.Display
End Sub