I
ielmrani via AccessMonster.com
Hi,
this code is fine but it doesnot loop. It only send one email (the top one
on the list of the table). How to fix it?
thanks in advance
Private Sub Command0_Click()
Dim db As Database
Dim rs As DAO.Recordset
'Dont't forget to reference the Outlook Object Library
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT Email FROM Table1")
Do Until rs.EOF
On Error GoTo ErrorHandler
With objEmail
.To = rs!Email
.Subject = "Happy Holidays"
.HTMLBody = "Greetings from CD <br><br>"
.Attachments.Add "P:\Greetings.jpg", olByValue, , "Stuff"
.Send
End With
ErrorHandler:
Resume Next
rs.MoveNext
Loop
this code is fine but it doesnot loop. It only send one email (the top one
on the list of the table). How to fix it?
thanks in advance
Private Sub Command0_Click()
Dim db As Database
Dim rs As DAO.Recordset
'Dont't forget to reference the Outlook Object Library
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT Email FROM Table1")
Do Until rs.EOF
On Error GoTo ErrorHandler
With objEmail
.To = rs!Email
.Subject = "Happy Holidays"
.HTMLBody = "Greetings from CD <br><br>"
.Attachments.Add "P:\Greetings.jpg", olByValue, , "Stuff"
.Send
End With
ErrorHandler:
Resume Next
rs.MoveNext
Loop