How to send email to everyone listed in a Table?

C

Carol in NJ

I have a database with over 1000 records - each record represents one person
and one of the fields is an email address. I want to send a message (the same
message to everyone) to everyone on the list who has an email entered into
the field.
 
P

pietlinden

I have a database with over 1000 records - each record represents one person
and one of the fields is an email address. I want to send a message (the same
message to everyone) to everyone on the list who has an email entered into
the field.

you open a recordset based on the table, then you loop through it,
either sending a single message to every e-mail address or you just
add them all to the BCC field. Then you set the message text and then
Send. You can use SendObject, but it's really limited. You should
have a look at the CDOSys library. It's on the MS website.
 
C

Carol in NJ

As a novice user, I'm not sure what you mean by "recordset" or "loop through
it." Please explain. I also found info from a previous thread discussing this
question also referring to the CDOSys library.Thanks.
 
T

Tom Wickerath

Hi Carol,

Take a look at this thread:

http://groups.google.com/group/micr..._frm/thread/280020a06d9226c6/404ef4621955d903

Message # 5 shows you an example of creating a DAO (Data Access Objects)
recordset, which loops through all records in a table named "tblPeople". The
e-mail addresses are in a field named "EmailAddress". This table also
includes a field of Yes/No data type named "blnActivePerson". A SQL
(Structured Query Language) statement uses this field in the criteria of the
query. Note that a part of the code is word wrapped for me, when I view this
message in Google groups:

Set rs = db.OpenRecordset("SELECT EmailAddress FROM tblPeople " _
& "WHERE EmailAddress Is Not Null AND
blnActivePerson<>0")

The last part, "blnActivePerson<>0")" should be on the second line, unless
you use a line continuation character (a space plus an underscore) as
indicated at the end of the first line. If you do not have this type of field
in your database, then change this line of code so that it reads something
like this:

Set rs = db.OpenRecordset("SELECT EmailAddress FROM tblPeople " _
& "WHERE EmailAddress Is Not Null)

Make the appropriate substitutions for your table and field names. Note: If
you used any spaces or other special characters, or reserved words, in the
name of your table, then you need to enclose these values in square brackets.
Something like this for a table named "Members List" and a field named
"E-mail Address":

Set rs = db.OpenRecordset("SELECT [E-mail Address] FROM [Members List] " _
& "WHERE [E-mail Address] Is Not Null)

To get started using this code, click on the Modules tab in your database.
Create a new module. Copy and paste the code from message # 5 into your new
module. Save the module, but make sure to give it a name different from any
procedure in your database. (A procedure is a subroutine or function). An
easy way to avoid duplicating names is to prefix the names of modules with
lowercase "bas" or "mod" (these are two common prefixes in use). So, for
example, you might name the module "basConcatenateUsers".

In order for this code to compile and run, you will need to have a reference
set to the "Microsoft DAO 3.6 Object Library" (use the 3.5 Object Library if
you are using Access 97). To check your references, click on Tools >
References when you are in the VBE (Visual Basic Editor).

Try the code in message # 5 first, before attempting the code in message #
2. For the present time, comment out the line of code towards the end of this
procedure, which reads:

SendMail strUsers, "This is a test message"

Do this by adding a single apostrophe at the beginning of this line of code.
It should turn green in color (assuming you have the default colors assigned
in the VBE options). Uncomment the line above this line of code by removing
the apostrophe:

' Debug.Print strUsers

After you have copied the code into a new module, saved it, and verified
that you have a reference set to the DAO Object library, try compiling the
code (Debug > Compile ProjectName). Hopefully the code will compile without
any errors. To run this code, have your mouse cursor blinking anywhere within
the function. Then press the F5 button. To see the results, open the
Immediate Window (Ctrl G), if it is not already open. To see what "looping
through" a recordset means, try adding a break point to the line of code that
reads:

Set db = CurrentDb()

or to any line that you want, except that you cannot add a break point to a
line that starts with Dim. To add a break point, click in the grey area that
is on the left hand side. You should see the line of code highlighted in
maroon. Then press the F5 button again. Notice that the code breaks at your
breakpoint. It breaks before executing the indicated line of code. To single
step through the code, press the F8 key. To advance to a second break point,
or to finish running the code if no more break points have been added, press
the F5 key. Note that while you are in break mode, you will not be able to
switch to a different group of objects, such as Tables.

Your 1000 records will most likely be a problem with your ISP (Internet
Service Provider), if you attempt to send one message to all users at the
same time. They will likely flag the message as spam. You'll need to do some
investigating with your ISP to see how many e-mail addresses that they allow
on an outgoing message. You might want to send the same message to, say, 40
people at a time. You could do this with a modification to the procedure, but
for now, just try this much and see if you have success printing a
concatenated list to your Immediate Window.


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
T

Tom Wickerath

PS. Regarding break points, delete this statement from my previous post:
Note that while you are in break mode, you will not be able to
switch to a different group of objects, such as Tables.

You won't be able to select a form in break mode, where the pop-up property
has been set to Yes. I guess that's what I was thinking when I wrote that.
Also, in order for break points to work, you need to have the option "Use
Access Special Keys" checked, under Tools > Startup.


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
 
T

Tony Toews [MVP]

Carol in NJ said:
As a novice user, I'm not sure what you mean by "recordset" or "loop through
it."

See the Sample Code illustrating looping through a DAO recordset page
at the Access Email FAQ at
http://www.granite.ab.ca/access/email/recordsetloop.htm

However this requires some basic familiarity with VBA code.

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
 
T

Tom Wickerath

Hi Tony,

Just a few suggestions regarding the code sample that you provided the link
to:

1.) Declare the recordset variable, RS, as a DAO recordset, to avoid a
compile error if the ADO recordset is included, and has a higher priority.
Otherwise, one will get a compile error on the line of code that reads:
RS.Edit.

2.) Declare the two variables "strTo" and "intMessageID", ie.:

Dim strTo As String, intMessageID As String

Consider renaming intMessageID as strMessageID. You must have written that
code without Option Explicit included.

3.) Perhaps explain the "Email - Outstanding Promos" should probably be a
query that includes a criteria to filter out any records where the field
cEmailAddress is null, or ZLS (zero length string). Otherwise, you get an
Error (94) Invalid use of Null error on the line of code that reads: strTo =
RS!cEmailAddress

4.) The line of code: lngRSCount = RS.RecordCount
will return an accurate count only if the table or query "Email -
Outstanding Promos" is a local table, because JET will attempt to open a
table-type recordset, since the type is not specified. If the table or query
is a linked object, OpenRecordset creates a dynaset-type Recordset, which
will not produce an accurate count until you first issue a .movelast
statement.

5.) Not sure why you have the Close statement, ie:

Set MyDB = Nothing
Close '<--------------------

since you have not opened a file for output using the Open statement.


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
T

Tom Wickerath

Correction:

4.) The line of code: lngRSCount = RS.RecordCount
will return an accurate count only if the table or query "Email -
Outstanding Promos" is a local table, ....

should read:

4.) The line of code: lngRSCount = RS.RecordCount will return an accurate
count only if the object "Email - Outstanding Promos" is a local table. If it
is a query, or a linked table, the assignment will include an incorrect
recordcount (1).


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
A

AnneMarie

This may be very simplistic (and only works if you have the Office Suite) but
you can use the "email merge" wizard in word to send emails out for an Access
query. Just set up a query that selects the email field (and ignores the
"null" email records) then let the wizard set up your email to send out thru
Outlook.
 
Top