Solved

Break up Record set

Posted on 2011-03-06
4
272 Views
Last Modified: 2013-11-27
Dear Experts,

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 Sub
        

End If

Me.WaitMessage.Visible = True

Dim rst As Recordset
    
    Set rst = CurrentDb.OpenRecordset("AllMembersLive")
    Do While Not rst.EOF

DoCmd.Save

Dim SEmailBody1 As String
Dim SEmailBody2 As String
Dim SEmailBody3 As String
Dim SEmailBody4 As String
Dim SEmailBody5 As String

SEmailBody1 =  "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 = False

EH:
      If Err.Number = 2501 Then
          Err.Clear
          Resume Next

     End If
End Sub

Open in new window

0
Comment
Question by:correlate
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 35054593
Remove line 58 and modify theses lines as below..

 (current line 14)  
      Dim rst As Recordset
    Dim BccList as string, x as integer
    Set rst = CurrentDb.OpenRecordset("AllMembersLive")
    Do While Not rst.EOF
    BccList = ""
    X=1
   Do until rst.eof or x>=50
     Bcclist =bcclist & "'" & rst!email
    x=x+1
    rst.movenext
   Loop
(current line 18)

Replace line 45 with
.To = BccList
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 35054968
> .. 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
0
 

Author Closing Comment

by:correlate
ID: 35055217
brilliant thanks for that
0
 

Author Comment

by:correlate
ID: 35055231
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
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question