Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Setup / Configuration / December 2003

Tip: Looking for answers? Try searching our database.

Sending email to a list of addresses from a query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Hettler - 24 Dec 2003 17:08 GMT
I have a table containing personnel information, which
includes an email address field.  I want to be able to run
a query based on certain criteria and return a list of
email addresses, and send a message to those addresses.  
Kind of like a mailmerge except it's an email-merge.  Is
there an easy way to do this?  If not, how about a hard
way?  Thanks.
Cheryl Fischer - 24 Dec 2003 17:20 GMT
Here is some code to get you started.  You will need to add a reference to
the Microsoft xx.x Outlook Object Library and the Microsoft DAO x.xx Object
Library appropriate to the version of Office that you are using.

Dim oApp As Outlook.Application
Dim objNewMail As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim db as DAO.Database
Dim rs As DAO.Recordset
Dim strSQL as String

Set oApp = New Outlook.Application

strSQL = "Select [email] from MyTable WHERE ..."
Set db = CurrentDB
Set rs = db.OpenRecordset(strSQL, DBOpenDynaset)

Set objNewMail = oApp.CreateItem(olMailItem)
With objNewMail
   rs.MoveFirst
  ' All recipients will get the same email
   Do While Not rs.EOF
       If Len(Trim(rs!email)) > 0 Then
           Set objOutlookRecip = .Recipients.Add(rs!email)
           objOutlookRecip.Type = olTo
       End If
       rs.MoveNext
   Loop
   .Subject = "Your subject here."
   .Body = "Your text message here."
   .Save
   .Send
End With

hth,

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

> I have a table containing personnel information, which
> includes an email address field.  I want to be able to run
[quoted text clipped - 3 lines]
> there an easy way to do this?  If not, how about a hard
> way?  Thanks.
Mark Hettler - 24 Dec 2003 19:10 GMT
Cheryl, looks like exactly what I need.  Thanks a million.

>-----Original Message-----
>Here is some code to get you started.  You will need to add a reference to
[quoted text clipped - 47 lines]
>
>.
Cheryl Fischer - 24 Dec 2003 19:16 GMT
You're welcome.

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

> Cheryl, looks like exactly what I need.  Thanks a million.
>
[quoted text clipped - 54 lines]
> >
> >.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.