Hi All,
I hope someone can work out why my emails wont loop through the recordset. Im very 'green' when it comes to vb so be gentle
What im trying to do is loop through a table of email address to send customers confirmations. I dont want to use the Docmd.send obj as it doesnt work all the time. See http://support.microsoft.com/default.aspx?scid=kb;en-us;Q262634
Anyway Whn i try and loop it says Loop without Do. Can someone please let me know where i should be dropping the do!!!
thanks!!
-------------------------------------------------
Private Sub cmd_send_emails_Click()
Dim rsEmail As ADODB.Recordset
Dim StrEmail As String
'Dim strUpdateEmail As sring
Dim ol As New Outlook.Application
Dim olMail As Outlook.MailItem
Set olMail = ol.CreateItem(olMailItem)
Set rsEmail = New ADODB.Recordset
rsEmail.ActiveConnection = CurrentProject.Connection
rsEmail.Open "Select * from w_imp_email"
rsEmail.MoveFirst
Do Until rsEmail.EOF
StrEmail = rsEmail.fields("billemail").Value 'sets email address value
'loops through until the end of the table
With olMail
.To = StrEmail
'.CC = "address1@aa.com"
'.BCC = "address2@aa.com"
'.Attachments.Add "c:\somefile.txt"
'.Attachments.Add "c:\secondfile.txt"
.Subject = "Testing"
.Body = "This is the body..."
.Send
Loop 'starts whole process over again
rsEmail.MoveNext 'goes to next record
End With
Set olMail = Nothing
Set ol = Nothing
Set rsEmail = Nothing 'closes table
----------------------
I hope someone can work out why my emails wont loop through the recordset. Im very 'green' when it comes to vb so be gentle
What im trying to do is loop through a table of email address to send customers confirmations. I dont want to use the Docmd.send obj as it doesnt work all the time. See http://support.microsoft.com/default.aspx?scid=kb;en-us;Q262634
Anyway Whn i try and loop it says Loop without Do. Can someone please let me know where i should be dropping the do!!!
thanks!!
-------------------------------------------------
Private Sub cmd_send_emails_Click()
Dim rsEmail As ADODB.Recordset
Dim StrEmail As String
'Dim strUpdateEmail As sring
Dim ol As New Outlook.Application
Dim olMail As Outlook.MailItem
Set olMail = ol.CreateItem(olMailItem)
Set rsEmail = New ADODB.Recordset
rsEmail.ActiveConnection = CurrentProject.Connection
rsEmail.Open "Select * from w_imp_email"
rsEmail.MoveFirst
Do Until rsEmail.EOF
StrEmail = rsEmail.fields("billemail").Value 'sets email address value
'loops through until the end of the table
With olMail
.To = StrEmail
'.CC = "address1@aa.com"
'.BCC = "address2@aa.com"
'.Attachments.Add "c:\somefile.txt"
'.Attachments.Add "c:\secondfile.txt"
.Subject = "Testing"
.Body = "This is the body..."
.Send
Loop 'starts whole process over again
rsEmail.MoveNext 'goes to next record
End With
Set olMail = Nothing
Set ol = Nothing
Set rsEmail = Nothing 'closes table
----------------------