How to Copy a list of records into a "TO" field of an email

H

Henry

Hello, I want to copy a list of email address from one of my table (called
Hotel Database) into the "To" of an email that I will then finish off
manually. I cannot and tried hard now to make this work; I am stuck with on
how to copy that list of emails (in a colum called "Email GM") onto the TO of
my email body. Here is my code below! thank you!!


Public Function SendEMail()

Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim recordEmailGM As Recordset

Set fso = New FileSystemObject

Subjectline$ = InputBox$("Please enter the subject line for this mailing.", _
"Subject Line Required!")

Set MyOutlook = New Outlook.Application

Set db = CurrentDb()

Set MailList = db.OpenRecordset("Email_GM", dbOpenTable) . THIS IS WHERE
IT DOES NOT WORK

Set MyMail = MyOutlook.CreateItem(olMailItem)

MyMail.To = MailList("email")

MyMail.Subject = Subjectline$

End Function
 
S

Stuart McCall

Henry said:
Hello, I want to copy a list of email address from one of my table (called
Hotel Database) into the "To" of an email that I will then finish off
manually. I cannot and tried hard now to make this work; I am stuck with
on
how to copy that list of emails (in a colum called "Email GM") onto the TO
of
my email body. Here is my code below! thank you!!


Public Function SendEMail()

Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim recordEmailGM As Recordset

Set fso = New FileSystemObject

Subjectline$ = InputBox$("Please enter the subject line for this
mailing.", _
"Subject Line Required!")

Set MyOutlook = New Outlook.Application

Set db = CurrentDb()

Set MailList = db.OpenRecordset("Email_GM", dbOpenTable) . THIS IS
WHERE
IT DOES NOT WORK

Set MyMail = MyOutlook.CreateItem(olMailItem)

MyMail.To = MailList("email")

MyMail.Subject = Subjectline$

End Function

From your description, this line:

Set MailList = db.OpenRecordset("Email_GM", dbOpenTable)

needs to be:

Set MailList = db.OpenRecordset("Hotel Database", dbOpenTable)

and this line:

MyMail.To = MailList("email")

needs to be:

MyMail.To = MailList("Email_GM")
 
T

Tony Toews [MVP]

As Stuart points out you need to change two lines to reference the
proper table and field names.

However you also need to loop through the "Hotel Database" recordset
fetching all the email address. With your current logic you'd only
read the first record.

For sample recordset logic see
http://www.granite.ab.ca/access/email/recordsetloop.htm

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top