Solved

Access VBA - send email for each record in a table

Posted on 2010-08-24
2
578 Views
Last Modified: 2013-11-27
Hi

I have an Access table with the records Email, Body, etc
How would I loop through all records automatically sending an email for each.

Thanks
0
Comment
Question by:murbro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 33514214
Something like this...
Sub SendEmail
 
    Dim olApp As Object, olMsg As Object
    Dim rs As DAO.Recordset
    
    Set olApp = CreateObject("Outlook.Application")
    Set rs = CurrentDb.OpenRecordset("NameOfTable")
 
    Do While Not rs.EOF
        If Nz(rs!EmailAddr, "") <> "" Then
            Set olMsg = olApp.CreateItem(0)
            With olMsg
                .To = rs!EmailAddr
                .Subject = rs!Subject
                .Body = rs!Body
                .Send
            End With
        End If
        rs.MoveNext
    Loop
 
    Set olMsg = Nothing
    Set olApp = Nothing
    rs.Close
    Set rs = Nothing
 
    MsgBox "Done"
 
End Sub

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 33514248
Thanks very much
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question