Changing the way my Sendmail function sends e-mails (1 Viewer)

slaterino

Registered User.
Local time
Today, 07:56
Joined
Dec 2, 2008
Messages
14
Hi,
I have created a Sendmail function on one of my pages but am having some problems getting it to work the way I want. At the moment it opens a seperate e-mail for every e-mail address in my query. How can I change the script below so that it opens just one e-mail with all the e-mail addresses listed under BCC rather than several e-mails, each with just one recipient?

Code:
Public Sub SendMail()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim strSubject As String
Dim strEmailAddress As String
Dim strEmailAddress2 As String
Dim strEMailMsg As String
Dim ingCounter As Integer
Dim intCount As Integer
    
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.CreateTextFile("C:\Email.htm", vbTrue)

        theFile.WriteLine "<HTML>"
        theFile.WriteLine "<BODY style='font-family:Century Gothic;'>"
        theFile.WriteLine "<p></p>"
        theFile.WriteLine [Message]
        theFile.WriteLine "<br />"

      ' theFile.WriteLine fso.OpenTextFile("K:\Admin & office\logo & letterhead\email-signature.html").ReadAll
        theFile.WriteLine "</BODY>"
        theFile.WriteLine "</HTML>"
        theFile.Close
        
        Set f = fso.OpenTextFile("C:\Email.htm", 1)
        MyHTML = f.ReadAll
        f.Close

strSubject = [Subject]
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("qryEmailOut")

rst.MoveFirst
Do Until rst.EOF
    
    strEmailAddress = rst![email address]
    strEMailMsg = MyHTML

    DoCmd.SendObject acSendNoObject, stDocName, acFormatRTF, , _
    , strEmailAddress, strSubject, strEMailMsg, , True
    
    rst.MoveNext
Loop
rst.Close
Set rst = Nothing

dbs.Close
Set dbs = Nothing

    DoCmd.SetWarnings False
    
    DoCmd.SetWarnings True
    
End Sub

Any help would be massively appreciated!
Thanks!
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 23:56
Joined
Aug 30, 2003
Messages
36,124
Build a string inside the loop:

strEmailAddress =strEmailAddress & rst![email address] & ";"

and move the SendObject line below the loop.
 

Users who are viewing this thread

Top Bottom