Use a query as an email distribution list

  • Thread starter Thread starter Kent
  • Start date Start date
K

Kent

How do I automatically cause a query with a list of email
addresses to paste into the "to" field in MS Outlook so I
can use it like a distribution list?
 
Are you using Outlook Automation or the SendObject method?

Do you want an individual email sent to each email address in your list or a
single email to all email addresses?
 
Here is some code suitable for use with Outlook Automation that will add
recipients from a recordset:

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

Set db = CurrentDB
Set rs = db.OpenRecordset("MyQuery", dbOpenDynaset)

Set oApp = New Outlook.Application

Set objNewMail = oApp.CreateItem(olMailItem)
With objNewMail
rs.MoveFirst
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 = "Test subject"
.Body = "Your text message here."
.Save
.Send
End With

rs.Close
Set rs = Nothing
 
Cheryl,
I'll give it a try. Thank you, Kent
-----Original Message-----
Here is some code suitable for use with Outlook Automation that will add
recipients from a recordset:

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

Set db = CurrentDB
Set rs = db.OpenRecordset("MyQuery", dbOpenDynaset)

Set oApp = New Outlook.Application

Set objNewMail = oApp.CreateItem(olMailItem)
With objNewMail
rs.MoveFirst
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 = "Test subject"
.Body = "Your text message here."
.Save
.Send
End With

rs.Close
Set rs = Nothing



--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX





.
 
Back
Top