gselliott
Registered User.
- Local time
- Today, 23:01
- Joined
- May 17, 2002
- Messages
- 106
I am wanting to loop through all records in a table where the field SEND is true. I have came up with the following after reading through some of the past posts but i am not really familiar with loops.
If Send = False Then
MsgBox "Please select users"
Exit Sub
End If
Dim NameSpace As Object
Dim EmailSend As MailItem
Dim EmailApp As Object
Set EmailApp = CreateObject("Outlook.Application")
Set NameSpace = EmailApp.GetNamespace("MAPI")
Set EmailSend = EmailApp.CreateItem(0)
Dim rsEmail As DAO.Recordset
Dim strEmail As String
Set rsEmail = CurrentDb.OpenRecordset("tbl")
Do While Send = True
rsEmail.MoveNext
EmailSend.Subject = "Information Systems - Hardware Audit"
EmailSend.HTMLBody = "TESTING"
EmailSend.Recipients.Add Email
EmailSend.Send
Loop
Set rsEmail = Nothing
MsgBox "Your Message has been sent successfully!"
End Sub
It seems to work fine for the first record in the table and an email message is sent, after that a runtime error is displayed saying "The Item has been moved or deleted"
If someone could point me in the right direction please i would be greatful!
Thanks
If Send = False Then
MsgBox "Please select users"
Exit Sub
End If
Dim NameSpace As Object
Dim EmailSend As MailItem
Dim EmailApp As Object
Set EmailApp = CreateObject("Outlook.Application")
Set NameSpace = EmailApp.GetNamespace("MAPI")
Set EmailSend = EmailApp.CreateItem(0)
Dim rsEmail As DAO.Recordset
Dim strEmail As String
Set rsEmail = CurrentDb.OpenRecordset("tbl")
Do While Send = True
rsEmail.MoveNext
EmailSend.Subject = "Information Systems - Hardware Audit"
EmailSend.HTMLBody = "TESTING"
EmailSend.Recipients.Add Email
EmailSend.Send
Loop
Set rsEmail = Nothing
MsgBox "Your Message has been sent successfully!"
End Sub
It seems to work fine for the first record in the table and an email message is sent, after that a runtime error is displayed saying "The Item has been moved or deleted"
If someone could point me in the right direction please i would be greatful!
Thanks