By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,222 Members | 1,133 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,222 IT Pros & Developers. It's quick & easy.

Sending E-mails to adresses in a table

P: n/a

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!!!

--
Dirk Goossens
May 12 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
DFS
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.Application, olItem As Outlook.MailItem
Set olApp = New Outlook.Application

Set rs = db.OpenRecordset("SELECT EmailTo, EmailCC FROM Table ORDER BY
EmailTo;")
Do Until rs.EOF

Set olItem = olApp.CreateItem(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.Attachments.Add evFile

If frm.checkAutoSend = 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

May 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.