melody.anne
Registered User.
- Local time
- Yesterday, 22:08
- Joined
- Feb 27, 2015
- Messages
- 43
I have this code that I want to work the following way: I have a list box, and I want the code to loop through the records, and populate the "send to" area of the e-mail.
To my understanding, the "NotesDoc.SendTo" and "NotesDoc.Subject parts aren't doing anything at all.
This code does populate the "Send To" field, but it opens a new e-mail for each recipient rather than put them all in the same e-mail Send To field (e.g. "e-mail1", "e-mail2", "e-mail3", etc).
It also sends an e-mail to every single person in the e-mails table rather than the selected ones. I don't know what to do to fix this, and I've Googled for answers for hours. Any help is appreciated.
Code:
Private Sub Command39_Click()
Dim MyDb As DAO.Database
Dim rsEmail As DAO.Recordset
Dim sToName As String
Dim sSubject As String
Dim sMessageBody As String
Dim Notesdb As Object
Dim NotesDoc As Object
Dim Notesrtf As Object
Dim NotesSession As Object
Set MyDb = CurrentDb()
Set rsEmail = MyDb.OpenRecordset("qryNames", dbOpenSnapshot)
With rsEmail
Set NotesSession = CreateObject("Notes.NotesSession")
Set Notesdb = NotesSession.GetDatabase("", "")
Call Notesdb.OpenMail
Rem make new mail message
Set NotesDoc = Notesdb.CreateDocument
.MoveFirst
Do Until rsEmail.EOF
If IsNull(.Fields(2)) = False Then
sToName = (.Fields(2) & ", ")
On Error Resume Next
NotesDoc.SendTo = Split(sToName & ", ")
NotesDoc.Subject = ("Reporte ")
Set Notesrtf = NotesDoc.CreateRichTextItem("body")
Call Notesrtf.appendtext("Report")
Call Notesrtf.addnewline(2)
Rem attach Error Report doc
's = ActiveDocument.Path + "\" + ActiveDocument.Name
Call Notesrtf.embedObject(1454, "", strCurrentPath, "Mail.rtf")
Rem send message
Call NotesDoc.Send(False)
Set NotesSession = Nothing
End If
.MoveNext
DoCmd.SendObject acSendReport, "rptName", acFormatPDF, sToName, , , sSubject
Loop
End With
Set MyDb = Nothing
Set rsEmail = Nothing
End Sub
To my understanding, the "NotesDoc.SendTo" and "NotesDoc.Subject parts aren't doing anything at all.
This code does populate the "Send To" field, but it opens a new e-mail for each recipient rather than put them all in the same e-mail Send To field (e.g. "e-mail1", "e-mail2", "e-mail3", etc).
It also sends an e-mail to every single person in the e-mails table rather than the selected ones. I don't know what to do to fix this, and I've Googled for answers for hours. Any help is appreciated.