Sending an email by clicking a form button?

  • Thread starter Thread starter Vanilla_Shake
  • Start date Start date
V

Vanilla_Shake

Does anybody know how to send an email by clicking a form
button? I have tried using SendObject but I need to be
able to pass the addressee names. Here is what I have if
I hard code it but I need help passing the names:

DoCmd.SendObject acNoObject, "rptName", acFormatSNP, _
, "Addresee name", , _
"Email Title", , True

Any help would be appreciated.
Thanks, Vanilla
 
What do you have as the source of E-mail addresses? Is it a table or are
you going to type them in? All you need to do is replace "Addressee
name" with a string variable containing semicolon separated list of
E-mail addresses:

Dim Str as String
Str = "(e-mail address removed);[email protected];[email protected]"
DoCmd.SendObject acNoObject, "rptName", acFormatSNP, , Str, , "Email
Title", , True

You can fill the string using a text control or from a recordset.
Pavel
 
If the addressees' names are not a part of the RecordSource for the current
form, you can use DAO to create a RecordSet and then loop through it to send
the emails.

Dim db as DAO.Database
Dim rs as DAO.Recordset
Dim strSQL as String

strSQL = "Select EmailAddr from SomeTable"
Set db as CurrentDB
Set rs as db.OpenRecordset(strSQL, dbOpenDynaset)

rs.MoveFirst
Do while not rs.EOF()
DoCmd.SendObject acSendReport, "rptName", acFormatSNP, rs!EmailAddr,
<cc>, <bcc>, <subject.>, <message>, False
Loop

rs.Close
Set rs=Nothing

The default for the last argument (Edit Message) is True, so if you want to
see each email before it is sent, leave off the last argument. If you want
the emails send without your viewing them, make the argument False
 
Back
Top