Dirk Goossens wrote:
Hi everybody
I have a table containing a list of E-mail adresses.
Is it possible to send an E-mail (one by one) to all the adresses?
Is it also possible to add an attachment?
Thanks for the helping hands!!!
Here's some code that will get you started. You'll need Outlook installed.
In your Access database, create a module and in the module you'll need to
set a reference (Tools | References) to 'Microsoft Outlook Object Library'.
(11.0 is the latest I think)
Then copy the following into a module
Public Sub genEmails()
dim response as byte, db as database, rs as RecordSet
set db = currentDb()
'CONFIRM BEGIN
Response = MsgBox("Begin generating emails?", vbYesNo)
If Response = vbNo Then Exit Sub
Dim olApp As Outlook.Applica tion, olItem As Outlook.MailIte m
Set olApp = New Outlook.Applica tion
Set rs = db.OpenRecordse t("SELECT EmailTo, EmailCC FROM Table ORDER BY
EmailTo;")
Do Until rs.EOF
Set olItem = olApp.CreateIte m(olMailItem)
olItem.To = rs("EmailTo")
olItem.CC = rs("EmailCC")
olItem.Subject = "Subject line"
olItem.Body = vbCrLf & "email body" & vbCrLf & vbCrLf
evFile = "C:\attachment. xls"
olItem.Attachme nts.Add evFile
If frm.checkAutoSe nd = True Then
olItem.Send
Else
olItem.Display
End If
Set olItem = Nothing
Response = MsgBox("Next email?", vbYesNo)
If Response = vbNo Then
rs.Close
exit sub
End If
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set olApp = Nothing
MsgBox "Finished processing emails"
End Sub