Hi,
I trying to write code that emails all email addresses in a table. at the moment the code only emails the first address and never moves to the next record. what am i doing wrong? The table is Called DC_Appointees_Test and the field is Appointee_Email. Here is the code:
Private Sub Command1_Click()
Dim olApp As Object
Dim objMail As Object
On Error Resume Next 'Keep going if there is an error
Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open
If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance
End If
'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.To = DLookup("[Appointee_Email]", "dc_appointees_test")
.Subject = "TEST "
.HTMLBody = "TEST "
.send
'.Display
.MoveNext
.Loop
End With
MsgBox "Close Box"
End Sub
I trying to write code that emails all email addresses in a table. at the moment the code only emails the first address and never moves to the next record. what am i doing wrong? The table is Called DC_Appointees_Test and the field is Appointee_Email. Here is the code:
Private Sub Command1_Click()
Dim olApp As Object
Dim objMail As Object
On Error Resume Next 'Keep going if there is an error
Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open
If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance
End If
'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.To = DLookup("[Appointee_Email]", "dc_appointees_test")
.Subject = "TEST "
.HTMLBody = "TEST "
.send
'.Display
.MoveNext
.Loop
End With
MsgBox "Close Box"
End Sub