Email BCC and pdf attachment (1 Viewer)

debbiedoobie10

Registered User.
Local time
Today, 00:59
Joined
Oct 1, 2010
Messages
13
I have a table named tblEmailCell that has a field named EmailAddress ( this is the email address I want to use). I have a query named qryMyEmailAddresses that pick 25 email address from tblEmailCell. Could someone help me write VBA to send a email with the EmailAddress in the bcc, the subject to be "Xmas Letter", attach a PDF and put the pdf in the body of the email. Thank you
 

pr2-eugin

Super Moderator
Local time
Today, 08:59
Joined
Nov 30, 2011
Messages
8,494
There are several posts on this Forum on creating a Outlook application object to send email.. Simply look down this post for similar threads.. If they do not answer your question search using the search function in this forum.. To get the address values, you need to create a recordset and then assign it to a string.. I have written a small function to do that..
Code:
Public Function getEmails() As String
    Dim bccStr As String
    Dim rstObj As Recordset 
    Set rstObj = CurrentDb.OpenRecordset("qryMyEmailAddresses")
    
    Do While Not rstObj.EOF
        bccStr = bccStr & rstObj.Fields("EmailAddress") & ";"
        rstObj.MoveNext
    Loop
    
    getEmails = Left(bccStr, Len(bccStr)-1)
End Function
so all you need is to assign it to the bcc of the Outlook object...
Code:
oulookObjectName.BCC = getEmails()
If you are stuck.. post back..
 

debbiedoobie10

Registered User.
Local time
Today, 00:59
Joined
Oct 1, 2010
Messages
13
Paul,

Do you know the code to attach the pdf to the email and in the body of the email. I need to put the from address in also.
 

nickblitz

Registered User.
Local time
Today, 15:59
Joined
Oct 29, 2012
Messages
30
There are several posts on this Forum on creating a Outlook application object to send email.. Simply look down this post for similar threads.. If they do not answer your question search using the search function in this forum.. To get the address values, you need to create a recordset and then assign it to a string.. I have written a small function to do that..
Code:
Public Function getEmails() As String
    Dim bccStr As String
    Dim rstObj As Recordset 
    Set rstObj = CurrentDb.OpenRecordset("qryMyEmailAddresses")
    
    Do While Not rstObj.EOF
        bccStr = bccStr & rstObj.Fields("EmailAddress") & ";"
        rstObj.MoveNext
    Loop
    
    getEmails = Left(bccStr, Len(bccStr)-1)
End Function
so all you need is to assign it to the bcc of the Outlook object...
Code:
oulookObjectName.BCC = getEmails()
If you are stuck.. post back..

where do insert oulookObjectName.BCC = getEmails() in? :eek:
 

Users who are viewing this thread

Top Bottom