Question : Access VBA - send email for each record in a table

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

Answer : Access VBA - send email for each record in a table

Something like this...

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
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
Random Solutions  
 
programming4us programming4us