mattkorguk
Registered User.
- Local time
- Today, 16:25
- Joined
- Jun 26, 2007
- Messages
- 301
Hi,
I'm trying to e-mail a document to a list of people. This document is a mailmerge document so it includes some of their details as well as their name etc. I also have another "template" document (also a merge document to the same list, and this is my .body text of the e-mail.
I seem to be missing a way of moving through the merge documents. The code below will create the 3 required e-mails (currently set to display for testing) but the .body of each e-mail relates to the first record only.
Also the attachment is still a merge document, but I'd like this to some how be specific to each record also.
It's so close I can almost smell it!!! I must be missing a simple .movenext or similar somewhere...
Thanks
I'm trying to e-mail a document to a list of people. This document is a mailmerge document so it includes some of their details as well as their name etc. I also have another "template" document (also a merge document to the same list, and this is my .body text of the e-mail.
I seem to be missing a way of moving through the merge documents. The code below will create the 3 required e-mails (currently set to display for testing) but the .body of each e-mail relates to the first record only.

Also the attachment is still a merge document, but I'd like this to some how be specific to each record also.
It's so close I can almost smell it!!! I must be missing a simple .movenext or similar somewhere...
Code:
Private Sub cmdTest_Click()
Dim rsEmail As DAO.Recordset
Dim strEmail As String
Dim oItem As Outlook.MailItem
Dim Datarange As Recipients
Dim oOutlookApp As Outlook.Application
Dim oDoc As Word.Application
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryDM-Export-Cases-Email", acViewNormal
Set oOutlookApp = GetObject(, "Outlook.Application")
Set rsEmail = CurrentDb.OpenRecordset("ll-mergeEmail")
strEmail = rsEmail.Fields("[Email Addr]").Value
message = "Enter the subject to be used for each e-mail message."
Title = "Email Subject"
mysubject = InputBox(message, Title)
Do While Not rsEmail.EOF
strEmail = strEmail
Set oDoc = CreateObject("Word.Application")
oDoc.Documents.Open ("C:\ll-Export\" & Me.selLetter.Value & ".doc")
strMessage = oDoc.ActiveDocument.Content
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.Subject = mysubject
.Body = strMessage
.To = rsEmail.Fields("[Email Addr]").Value
.Attachments.Add Me.fPath.Value, olByValue, 1, "Important Information"
.Display
End With
rsEmail.MoveNext
Loop
oDoc.Application.Quit
Set rsEmail = Nothing
Set oLetter = Nothing
End Sub
Thanks