Seems like this question has been beat to death but I've yet to find anything that works for me.
Access 2003
I've got a form with a drop down that runs a query with many email addresses in a field called "EmailAddress" by default. This field is in column 4, after a few other fields. I'd like to pull those email addresses from the results of the query, pass them to a variable, then based on that variable, create an email with those values seperated by colons without automatically sending it.
I've tried this code but could not get it to work:
Dim MyDb As DAO.Database
Dim rsEmail As DAO.Recordset
Dim sToName As String
Dim sSubject As String
Dim sMessageBody As String
Set MyDb = CurrentDb()
Set rsEmail = MyDb.OpenRecordset("My Query", dbOpenSnapshot)
With rsEmail
.MoveFirst
Do Until rsEmail.EOF
If IsNull(.Fields(4)) = False Then
sToName = .Fields(4)
sSubject = "Subject"
sMessageBody = "Email Body"
DoCmd.SendObject acSendNoObject, , , _
sToName, , , sSubject, sMessageBody, False, False
End If
.MoveNext
Loop
End With
Set MyDb = Nothing
Set rsEmail = Nothing
Access 2003
I've got a form with a drop down that runs a query with many email addresses in a field called "EmailAddress" by default. This field is in column 4, after a few other fields. I'd like to pull those email addresses from the results of the query, pass them to a variable, then based on that variable, create an email with those values seperated by colons without automatically sending it.
I've tried this code but could not get it to work:
Dim MyDb As DAO.Database
Dim rsEmail As DAO.Recordset
Dim sToName As String
Dim sSubject As String
Dim sMessageBody As String
Set MyDb = CurrentDb()
Set rsEmail = MyDb.OpenRecordset("My Query", dbOpenSnapshot)
With rsEmail
.MoveFirst
Do Until rsEmail.EOF
If IsNull(.Fields(4)) = False Then
sToName = .Fields(4)
sSubject = "Subject"
sMessageBody = "Email Body"
DoCmd.SendObject acSendNoObject, , , _
sToName, , , sSubject, sMessageBody, False, False
End If
.MoveNext
Loop
End With
Set MyDb = Nothing
Set rsEmail = Nothing