My company produces a weekly newsletter and have an MS Access 2010 database which sends out the newsletter (it's an attachment) one at a time. This works, however it sits on a network and takes a bit of time to run & every so often the connection to the network momentarily stops and then the sending fails as it can't pick up the attachment.
What I would like to do therefore is to group the recordset into blocks of 50 and BCC the recipients instead. Does anybody have a piece of code which will take the first 50 recipients from the query "AllMembersLive" (the field name for the email address is "Email"), and save the email in outlook drafts. It would then go back and repeat that for the next 50 etc etc.
The membership list does change so I am keen not to have a "static" peice of code, by which I mean I would need to hard code in the "next 50" a set number of times.
Can anybody help
Private Sub Command2_Click() If Len(Me!txtFileName & "") = 0 Then MsgBox "The AM Update has not been attached!!", , "Warning" Cancel = True Exit SubEnd IfMe.WaitMessage.Visible = TrueDim rst As Recordset Set rst = CurrentDb.OpenRecordset("AllMembersLive") Do While Not rst.EOFDoCmd.SaveDim SEmailBody1 As StringDim SEmailBody2 As StringDim SEmailBody3 As StringDim SEmailBody4 As StringDim SEmailBody5 As StringSEmailBody1 = "Email text - removed for privacy"SEmailBody2 = "Email text - removed for privacy"SEmailBody3 = "Email text - removed for privacy" Dim mess_body As String Dim appOutLook As Outlook.Application Dim MailOutLook As Outlook.MailItem Set appOutLook = CreateObject("Outlook.Application") Set MailOutLook = appOutLook.CreateItem(olMailItem) Set appOutLook = CreateObject("Outlook.Application") Set MailOutLook = appOutLook.CreateItem(olMailItem) With MailOutLook .BodyFormat = olFormatRichText .To = rst!Email .Subject = "Correlate Search - Weekly Update, " & Date .HTMLBody = SEmailBody1 & SEmailBody2 & SEmailBody3 If Left(Me.txtFileName, 1) <> "<" Then .Attachments.Add (Me.txtFileName) End If .DeleteAfterSubmit = True 'This would let Outlook send the note without storing it in your sent bin .Send End With 'MsgBox MailOutLook.Body 'Exit Sub rst.MoveNext Loop rst.Close Set rst = Nothing MsgBox "The AM Update has been sent!!", , "Success" Me.WaitMessage.Visible = FalseEH: If Err.Number = 2501 Then Err.Clear Resume Next End IfEnd Sub
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
> .. it sits on a network and takes a bit of time to run & every so often
> the connection to the network momentarily stops
This should not happen so this is what you should work with.
You can start by moving all this:
Dim mess_body As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
to the top before the loop.
/gustav
Tom Crowfoot
ASKER
brilliant thanks for that
Tom Crowfoot
ASKER
Hi, cactus_data
Thanks for the comment there, I was unable to close off the question as the EE site was down for work & this solutions seems to be all fine
many thanks
Your help has saved me hundreds of hours of internet surfing.
> the connection to the network momentarily stops
This should not happen so this is what you should work with.
You can start by moving all this:
Dim mess_body As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Appl
Set MailOutLook = appOutLook.CreateItem(olMa
Set appOutLook = CreateObject("Outlook.Appl
Set MailOutLook = appOutLook.CreateItem(olMa
to the top before the loop.
/gustav