Automatically send email

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need my databases to generate a reminder email automatically, based on
date. For example: when 30 days has passed since the last meter read send
employee an email saying that it is time to do aonther meter read. The
program that I would be sending the email to would be MSOutlook.
 
Access has the SendObject method that you can use to do this. Check the
online help for specific syntax on sending the message.

To determine the time interval, you can do something like this;

If DateAdd("d",-30,Date) > YourDateField Then
DoCmd.SendObject , , , (e-mail address removed)", , , "Time to Read the
Meter", "Get to work NOW", True
End IF

If you add this code to your Startup form's Load or Open event, it'll run
each time your database is opened. If you want to do this without
interaction, you'd have to build a new database, build a startup form that
included this code in the Load or Open event, set the form as your Startup
form, and then use the builtin Windows scheduler to "run" this database each
day ...

If you need to loop through a table to determine whether you need to send an
email or not, then you'll need to generate a recordset to do this:

Dim rst As DAO.Recordset

Set rst = CurrentDB.OpenRecorset("SELECT strEmail, strName FROM YourTable
WHERE DateAdd("d", -30, Date) > SomeDateField")

Do Until rst.EOF
DoCmd.SendObject ,,,rst("strEmail"),,,"Time to work","Get To Work", False
rst.MoveNext
Loop

Set rst = Nothing

However, be aware that calling SendObject in a loop can cause problems, and
that running code like this unattended will most likely cause Outlook to
prompt you with the standard security warnings ("Are you sure you want to
allow this?")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top