I am trying to get a conditional loop working, but can't seem to get the condition statement in the correct place to work for each record.
I want to loop through a table and send an email to each record unless I have checked an EXCLUDE field in the form. So somewhere I need
"If EXCLUDE = "Yes" then goto the next record" or similar so that it misses out any record set EXCLUDE = Yes on each loop until EOF.
Where and what statements?
Thanks.
I want to loop through a table and send an email to each record unless I have checked an EXCLUDE field in the form. So somewhere I need
"If EXCLUDE = "Yes" then goto the next record" or similar so that it misses out any record set EXCLUDE = Yes on each loop until EOF.
Where and what statements?
Thanks.
Code:
Private Sub Command11_Click()
Dim address As String
Dim Name As String
Dim EXCLUDE As String
Dim db As Database
Dim rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("MYTABLE", dbOpenTable)
Me.Refresh
rst.MoveFirst
Do While Not rst.EOF
Name = Trim(rst!Name)
address = Trim(rst!Email)
Dim mail As CDO.Message
Dim config As CDO.Configuration
Set mail = CreateObject("CDO.Message")
Set config = CreateObject("CDO.Configuration")
config.Fields(cdoSMTPAuthenticate).Value = cdoBasic
config.Fields(cdoSendUserName).Value = "MYUSERNAME"
config.Fields(cdoSendPassword).Value = "MYPASSWORD"
config.Fields(cdoSendUsingMethod).Value = cdoSendUsingPort
config.Fields(cdoSMTPServer).Value = "MYSMTP"
config.Fields(cdoSMTPUseSSL).Value = True
config.Fields(cdoSMTPServerPort).Value = MYPORT
config.Fields.Update
Set mail.Configuration = config
With mail
.To = [address]
.From = "MY FROM"
.subject = "MY SUBJECT"
.HTMLBody = "Dear " & [Name] & "," _
& "<br>" _
& "<br>" _
html = html & "</tr>"
.Send
End With
rst.Edit
rst!EMAIL_DATE = (Now())
rst.Update
Me.Refresh
Set config = Nothing
Set mail = Nothing
rst.MoveNext
Loop
End Sub