Creating a function to automated this command! (EMAIL)



Hey guys.....
Okay I need to some help with code please....I need to query my
database....look for the "DueDate" Field, if it is within the next two
months....then I need it to Run a Command I have already written which
is as follows :

Private Sub Command38_Click()
Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String

strTo = Me!EmailAddress
strsubject = "subject"
varbody = "Attached please find your confirmation"

Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo
olMail.Subject = strsubject
olMail.Body = varbody


Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing

End Sub

How would I go about this>?






Sorry guys...let me explain the situation a little-bit better....I also

have a Form (A continous form) that is essentially a Summary List of
all the records in my database (i.e It contains each records name, the
records Issue date, and its DueDate) for ALL the records in the
database....and from this the user can click on which record they want
and it will then open this particular record that exihibits much more
information, naturally! HOWEVER this is getting off the track!

Back on I need to create on "On Load" Event that will cycle

through all of the "DueDate" fields in this Summary List form...that
will then execute my email command if the "DueDate" falls within the
critera? (I already have the email aspect under control) I just need to

essentially automate the process.

If I do have to create an "On Load" event that will check these records

"DueDate", can I also pass some of the record information to the email
command (the code is posted in my previous question...above) ? if so
how do I do this?

WHat I have come up with so the theory for my "On Load" event

is as follows:

Private Sub Form_Load()
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("qryShipsInformation")

If DateDiff("m", RS(), Date) < 2 Then DoCmd.Run Emailer ()

'do something - send an email, flag something...

End If

Obviously doesnt work....just theory at the moment....any
suggestions...much appreciated!

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