Access Auto Reminder

G

Guest

I have a query that calls up projects that are not marked as complete, are
due in 30 days, 15 days, 5 days, or now. The query contains the Responsible
party name and email. I need this to run everyday at 6 AM and send an email
to the appropriate person. I'm getting closer I think, but can't get anything
to work. I also read that I would need to make a new db to make this run
automatically??

HELP!!!! Thank you!!

ddunks
 
J

John Vinson

I have a query that calls up projects that are not marked as complete, are
due in 30 days, 15 days, 5 days, or now. The query contains the Responsible
party name and email. I need this to run everyday at 6 AM and send an email
to the appropriate person. I'm getting closer I think, but can't get anything
to work. I also read that I would need to make a new db to make this run
automatically??

HELP!!!! Thank you!!

ddunks

I can't imagine that you'll need a new database... but since we cannot
see your database, know nothing about its structure, nor can we see
what you've done so far, it's more than a bit difficult to be specific
with our help.

Some points (which you may or may not have already solved):

- You can use Windows Scheduler to open the database every morning at
6. I'd suggest using the runtime /x switch to execute a Macro, which
would have just one RunCode line to execute VBA code to run your
queries and send the email.
- You can use Queries with criteria on the date field such as

<= DateAdd("d", 30, Date())

to find records with the date field coming up in the next 30 days.
- Check out Tony Toews' email FAQ site for details on sending EMails:
http://www.granite.ab.ca/access/email.htm

John W. Vinson[MVP]
 
G

Guest

Thanks! This led me on the right path. I have the scheduler set up for 6 am.
I have the code below working if I have one email in the Body File - but how
do get through more than one? When I uncomment where it says to for it to
loop, it does not work. It also messes up on the End Function.

Option Compare Database
Option Explicit

Public Function SendEMail()

Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String

Set fso = New FileSystemObject

' First, we need to know the subject.
' We can't very well be sending around blank messages...

Subjectline$ = "ePRAM Suggestions"

' If there's no subject, call it a day.

If Subjectline$ = "" Then
MsgBox "No subject line, no message." & vbNewLine & vbNewLine & _
"Quitting...", vbCritical, "E-Mail Merger"
Exit Function
End If

' Now we need to put something in our letter...

BodyFile$ = "I:\CSC\EPRAM\Email.txt"

' If there's nothing to say, call it a day.

If BodyFile$ = "" Then
MsgBox "No body, no message." & vbNewLine & vbNewLine & _
"Quitting...", vbCritical, "I Ain't Got No-Body!"
Exit Function
End If

' Check to make sure the file exists...
If fso.FileExists(BodyFile$) = False Then
MsgBox "The body file isn't where you say it is. " & vbNewLine &
vbNewLine & _
"Quitting...", vbCritical, "I Ain't Got No-Body!"
Exit Function
End If

' Since we got a file, we can open it up.
Set MyBody = fso.OpenTextFile(BodyFile, ForReading, False,
TristateUseDefault)

' and read it into a variable.
MyBodyText = MyBody.ReadAll

' and close the file.
MyBody.Close

' Now, we open Outlook for our own device..
Set MyOutlook = New Outlook.Application


' Set up the database and query connections

Set db = CurrentDb()

Set MailList = db.OpenRecordset("MyEmailAddresses")

' now, this is the meat and potatoes.
' this is where we loop through our list of addresses,
' adding them to e-mails and sending them.

'Do Until MailList.EOF

' This creates the e-mail

Set MyMail = MyOutlook.CreateItem(olMailItem)

' This addresses it
MyMail.To = MailList("email")

'This gives it a subject
MyMail.Subject = Subjectline$

'This gives it the body
MyMail.Body = MyBodyText


'If you want to send an attachment
'uncomment the following line



' To briefly describe:
' "c:\myfile.txt" = the file you want to attach
'
' olByVaue = how to pass the file. olByValue attaches it,
olByReference creates a shortcut.
' the shortcut only works if the file is available locally
(via mapped or local drive)
'
' 1 = the position in the outlook message where to attachment
goes. This is ignored by most
' other mailers, so you might want to ignore it too. Using
1 puts the attachment
' first in line.
'
' "My Displayname" = If you don't want the attachment's icon
string to be "c:\myfile.txt" you
' can use this property to change it to something useful,
i.e. "4th Qtr Report"



'This sends it!
'MyMail.Send

'Some people have asked how to see the e-mail
'instead of automaticially sending it.
'Uncomment the next line
'And comment the "MyMail.Send" line above this.

MyMail.Display



'And on to the next one...
'MailList.MoveNext

'Loop

'Cleanup after ourselves

Set MyMail = Nothing


'Uncomment the next line if you want Outlook to shut down when its done.
'Otherwise, it will stay running.

'MyOutlook.Quit
Set MyOutlook = Nothing

MailList.Close
Set MailList = Nothing
db.Close
Set db = Nothing

End Function
 
G

Guest

Its working!!!!! Woo Hoo!!

What do you suggest as the best reading material for learning the code? I
think I hurt myself trying to think about this stuff :) I need more work for
sure!

Thanks Arvin and John!!

ddunks
 

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

Top