View Full Version : Sending E-mail based on query results...


Mitch_____W
11-09-2001, 03:06 AM
I have a query which basically querys by date (specifically: <Date()-30) I would like to have an email notice sent to certain individuals if the query finds any dates within the criteria. I was trying to do it with a module but I don't know haw to reference the query as an object or to check the query to see if any criteria matches were found after the query was run. Anyon got any ideas?

BukHix
11-09-2001, 05:04 AM
This should do it for you:

Dim rsEmail As DAO.Recordset
Dim strEmail As String
Set rsEmail = CurrentDb.OpenRecordset("YourQuery")

Do While Not rsEmail.EOF
strEmail = rsEmail.Fields("EmailAddress").Value
DoCmd.SendObject , , , strEmail, , , "Subject", "Message Text"

rsEmail.MoveNext

Loop
Set rsEmail = Nothing
--------------------------------------------------

Then make sure you change these to match the names in your table/query.

"YourQuery" = Table or Query Name.
"EmailAddress" = Field in Table or Query holding the email address.

This will loop through an entire table or query sending an email to everyone in it