Add Selected Recipients to BCC in New Email (1 Viewer)

Anonymous1986

Registered User.
Local time
Today, 06:58
Joined
Mar 20, 2019
Messages
23
Hello all

Can anyone help with vba so that selected emails add to bcc in new Outlook email? Found a few helpful threads but think i need it really broken down from the start for me.

I want to select checkbox on form and then on click of command button open email with selected recipients in bcc field so that i can type all other necessary fields.

Thanks in advance!
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:58
Joined
Oct 29, 2018
Messages
21,449
Hi. There are two ways (at least) to start an email from Access. The simplest one is to use the SendObject method. For example:
Code:
DoCmd.SendObject acSendNoObject, Bcc:="your list of recipients here", Edit:=True
 

Anonymous1986

Registered User.
Local time
Today, 06:58
Joined
Mar 20, 2019
Messages
23
Thanks for quick response!

What would i substitute "your list of recipients for"? This could change at different times.

Otherwise is there a way to do so from a query as i have got that far?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:58
Joined
Oct 29, 2018
Messages
21,449
Thanks for quick response!

What would i substitute "your list of recipients for"? This could change at different times.

Otherwise is there a way to do so from a query as i have got that far?
Hi. If you have the list of recipients in a query, you could maybe use this simple function to put them in the BCC argument.
 

Anonymous1986

Registered User.
Local time
Today, 06:58
Joined
Mar 20, 2019
Messages
23
I'm sorry I need this in the simplest terms!

Attached is now my vba. Please can you advise where I need to amend?

thank you.
 

Attachments

  • OnClick Screenshot.jpg
    OnClick Screenshot.jpg
    36.2 KB · Views: 64

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:58
Joined
Oct 29, 2018
Messages
21,449
I'm sorry I need this in the simplest terms!

Attached is now my vba. Please can you advise where I need to amend?

thank you.
Hi. Unfortunately, there's a few things off with your code. Wouldn't it be simpler yet if you could post a copy of your db with test/dummy data instead?
 

murray83

Games Collector
Local time
Today, 06:58
Joined
Mar 31, 2017
Messages
728
you could have a a list of email address asgined to certain people then have a text box on your form and use that as a string like i did for the .to in the below

Code:
'email script
Public Sub CreateEmailWithOutlook()

Forms!frmMain.Requery

'bits for the attachment
Dim myPath As String
Dim sTo As String
Dim pDHL As String  'to try and add the dhl logo
Dim pSAIN As String 'to try and add the sainsburys logo

    pDHL = "G:\GENERAL\PCC\Compliance\Compliance Database\SigPictures\dhl.jpg"  'dhl logo path
    pSAIN = "G:\GENERAL\PCC\Compliance\Compliance Database\SigPictures\sainsburys.jpg"  'sainsburys logo path
    sTo = Forms!frmMain!txtHiddenEmail.Value

    myPath = "G:\GENERAL\PCC\Compliance\Compliance Database\FailureReport\"
    strReportName = "Failure Report.pdf"
        

    ' Create a new email object
    Set olApp = CreateObject("Outlook.Application")
    Set olMailItem = olApp.createitem(olMailItem)

    ' Add the To/Subject/Body to the message and display the message
    With olMailItem
        .To = sTo
        .cc = "PCCMgr.DAVEDepot@sainsburys.co.uk"
        .Subject = "PCC Supplier Compliance Failure Notification"
        .HTMLBody = "<html><body><font face=calibri>Dear Supplier,<br><br>Please find attached a non-compliance form and photos, for Pre-advice XXXXXXXX<br><br>If you have any questions regarding the above compliance failures please reply to this email within 14 days to contest or request further information. <br><br>If this compliance issue is not contested, we will decide, what we believe is the best outcome. <br><br>Issues cannot be queried after the 14 day period is over. <br><br> Kind Regards <br><br>Christopher Mawby<br>PCC Compliance Administrator<br>Sainsbury's Distribution Centre <br>Daventry International Rail Freight Terminal <br>Brassey Way <br>Kilsby <br>CV23 8BQ<br><br> <A HREF=mailto:QC.DAVEDepot@sainsburys.co.uk>QC.DAVEDepot@sainsburys.co.uk</A><br>Tel: 01788 206630 <br> <img src ='" & pDHL & "'> For <img src ='" & pSAIN & "'> </font> </body> </html>"
        .Attachments.Add myPath & strReportName 'FileName"
        .Display    ' Displays before sending the message
    End With


    ' Release all object variables
    Set olMailItem = Nothing
    Set olApp = Nothing
    
    DoCmd.Close acReport, "rpt_FailureReport"
    
End Sub

just instead of the .to put it at the .bcc part
 

Anonymous1986

Registered User.
Local time
Today, 06:58
Joined
Mar 20, 2019
Messages
23
I've rewritten code as below but think i still need to tweak


Private Sub Command146_Click()

'email script
Public Sub CreateEmailWithOutlook()

Forms!SubcontractorListBulkEmail.Requery


sTo = Forms!SubcontractorListBulkEmail!Text165.Value


' Create a new email object
Set olApp = CreateObject("Outlook.Application")
Set olMailItem = olApp.CreateItem(olMailItem)

' Add the To/Subject/Body to the message and display the message
With olMailItem
.BCC = sTo
.Display ' Displays before sending the message
End With


' Release all object variables
Set olMailItem = Nothing
Set olApp = Nothing

End Sub


A few other points I'm not sure if could be the cause:



1 - where should my text box be bound to? I've tried the query and also the table but both returning #NAME? error. If the table, I'm certain my expression is wrong.

2 - I have embedded macro already on click of command button. Does this matter then when trying to put code in also?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:58
Joined
Oct 29, 2018
Messages
21,449
Hi. Are you not able to post a demo copy of your db with test data? Just curious...
 

Anonymous1986

Registered User.
Local time
Today, 06:58
Joined
Mar 20, 2019
Messages
23
I've tried to do so before and it was a struggle so it's not something i can do very quickly. Also my tables are linked ...
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:58
Joined
Oct 29, 2018
Messages
21,449
I've tried to do so before and it was a struggle so it's not something i can do very quickly. Also my tables are linked ...
Hi. We just need a "demo." It doesn't have to be the "whole" db. Just give us something similar to what you're working with, so we can show you what to do. For example, the demo could contain only one table with dummy data for the email list. One query similar to the one you're trying to use now. And one form to mimic how you're trying to send an email.
 

Anonymous1986

Registered User.
Local time
Today, 06:58
Joined
Mar 20, 2019
Messages
23
Even stripped down it's 4.59mb which exceeds the allowance i can upload and then when zipped it's just over at 2.59mb!!
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:58
Joined
Oct 29, 2018
Messages
21,449
Even stripped down it's 4.59mb which exceeds the allowance i can upload and then when zipped it's just over at 2.59mb!!
How about exporting only the required objects to a new, blank database? Just a thought...
 

murray83

Games Collector
Local time
Today, 06:58
Joined
Mar 31, 2017
Messages
728
Anonymous1986, the text box wouldn't be bound to anything would work with dlookup like in my example attached, to run it just

click on the button and the input for supplier

000000

and then date put

19/6/19

and it runs feel free to use the code

hope it helps
 

Attachments

  • email example.accdb
    1,004 KB · Views: 50
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:58
Joined
Oct 29, 2018
Messages
21,449
Think i actually had to do that last time. Thanks
Hi. The form you included doesn't open because it's missing a table. So, I created a new form you could try. Let me know what happens when you try it.
 

Attachments

  • Dummy Database.zip
    35.9 KB · Views: 52

Users who are viewing this thread

Top Bottom