In this post, we will be showing you how to use the CC and BCC fields.
Why BCC? The BCC field means Blind Carbon Copy and is very useful if you want to send multiple emails at once but you don’t want the recipients to know who else received the email.
The Code
The main changes to the code are in Section 2.
Public Function usingTheBCCField(strSQL As String, strEmailField As String, strMainEmail As String, _ strSubject As String, strMessage As String) On Error GoTo ErrorHandler '''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''' 1 '''''''''''''''''''' ''''''''''''''''''' Declarations ''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim olApp As Object Dim olMail As Outlook.MailItem Dim olRecipient As Outlook.Recipient Dim olAttachment As Outlook.Attachment Dim db As DAO.Database Dim rs As DAO.Recordset ' Create the Outlook session. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'if outlook is open it will need to be run as administrator '''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Set olApp = New Outlook.Application Set olMail = olApp.CreateItem(olMailItem) '''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''' 2 '''''''''''''''''''' ''''''''''''''''''' Recipients ''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''' 'open up a recordset and move through it Set db = CurrentDb Set rs = db.OpenRecordset(strSQL) With rs If Not .BOF And Not .EOF Then .MoveLast .MoveFirst While (Not .EOF) ' Add the To recipient(s) to the message. Set olRecipient = olMail.Recipients.Add(.Fields(strEmailField)) olRecipient.Type = olBCC .MoveNext Wend End If End With 'will need to add a recipient. Add yourself so you can monitor where the emails have gone. Set olRecipient = olMail.Recipients.Add(strMainEmail) olRecipient.Type = olTo '''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''' 3 '''''''''''''''''''' ''''''''''''''''''''' Message''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''' With olMail ' Set the Subject, Body, and Importance of the message. .Subject = strSubject .Body = strMessage .Importance = olImportanceHigh 'High importance ' Resolve each Recipient's name. For Each olRecipient In .Recipients olRecipient.Resolve Next '''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''' 4 '''''''''''''''''''' ''''''''''''''' Display, Save, Send''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''' .Display End With usingTheBCCField = True ExitFunction: Set olRecipient = Nothing Set olMail = Nothing Set olApp = Nothing Exit Function ErrorHandler: usingTheBCCField = False Resume ExitFunction End Function
The Explanation
Public Function usingTheBCCField(strSQL As String, strEmailField As String, strMainEmail As String, _ strSubject As String, strMessage As String)
We have added an argument to the usingTheBCCField function (strEmailField). When using the BCC field, we still need to have at least one email address in the “To” field. In this case, companies will often use their own email address (e.g. info@somecompany.com) in the “To” field.
... While (Not .EOF) ' Add the To recipient(s) to the message. Set olRecipient = olMail.Recipients.Add(.Fields(strEmailField)) olRecipient.Type = olBCC .MoveNext Wend ...
From Section 2.
The key line here is…
olRecipient.Type = olBCC
…as it simply changes the type of recipient from the standard “To” type to a BCC field. Change this to olCC for the CC field.
Set olRecipient = olMail.Recipients.Add(strMainEmail) olRecipient.Type = olTo
As stated, we will need to add a recipient to the “To” field. We are using the strMainEmail argument for the “To” field.
Testing The Function
The Form
We have added the extra field to the form.
Clicking on the Test button will produce this result:
The Conclusion
Using the BCC field is very good way to be able to send multiple emails whilst hiding the recipients from each other.
In the next post, we will be showing you how to add attachments to your emails.