' Set up constants and objects
Dim conn, rs, outlookApp, mailItem
' Create a connection to the Access database
Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Path\To\YourDatabase.accdb;"
' Open a recordset for the table (replace 'YourTableName' with your actual table name)
Set rs = conn.Execute("SELECT EmailAddress, Subject, Body FROM YourTableName")
' Create Outlook application object
Set outlookApp = CreateObject("Outlook.Application")
' Loop through the recordset and send emails
Do Until rs.EOF
If Not IsNull(rs("EmailAddress")) Then
' Create a new email item
Set mailItem = outlookApp.CreateItem(0)
mailItem.To = rs("EmailAddress")
mailItem.Subject = rs("Subject")
mailItem.Body = rs("Body")
' Send the email (use Display instead of Send for previewing)
mailItem.Send
End If
' Move to the next record
rs.MoveNext
Loop
' Clean up
rs.Close
conn.Close
Set mailItem = Nothing
Set outlookApp = Nothing
Set rs = Nothing
Set conn = Nothing
MsgBox "Emails sent successfully!"