Send email

E

EMILYTAN

Hey I have this code for sending email which I get it from MS HELP.
I want to send email when txtAgedDay = -1 and I want it to automatically send
without I need to open the form and it can only send once...Any idea?

Sub SendMessage(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("(e-mail address removed)")
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("(e-mail address removed)")
objOutlookRecip.Type = olCC

' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "Last test - I promise." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send

End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
 
E

EMILYTAN via AccessMonster.com

What is the difference between .Display and .Send?
I changed already but still cannot send automatically and once I open that
form on that particular record, it send the mail and i open again, it send
again...
I just want it to send automatically once i open the database without opening
the form and send only once....
Any idea?
Perry said:
replace
objOutlookMsg.Display
by
objOutlookMsg.Send

Hey I have this code for sending email which I get it from MS HELP.
I want to send email when txtAgedDay = -1 and I want it to automatically
[quoted text clipped - 45 lines]
Set objOutlook = Nothing
End Sub
 
E

EMILYTAN via AccessMonster.com

Help!!!!
EMILYTAN said:
What is the difference between .Display and .Send?
I changed already but still cannot send automatically and once I open that
form on that particular record, it send the mail and i open again, it send
again...
I just want it to send automatically once i open the database without opening
the form and send only once....
Any idea?
replace
objOutlookMsg.Display [quoted text clipped - 7 lines]
Set objOutlook = Nothing
End Sub
 
C

Carl Rapson

EMILYTAN via AccessMonster.com said:
Help!!!!
EMILYTAN said:
What is the difference between .Display and .Send?
I changed already but still cannot send automatically and once I open that
form on that particular record, it send the mail and i open again, it send
again...
I just want it to send automatically once i open the database without
opening
the form and send only once....
Any idea?
replace
objOutlookMsg.Display
[quoted text clipped - 7 lines]
Set objOutlook = Nothing
End Sub

Display will open the email in a preview window, while Send sends the email
without previewing.

Do you want the email to send automatically when you open the database or
just a specific form? If it's the database, you can set up a macro that
calls your email sub and set that macro to run automatically at startup. If
it's the form, you can put the code in the Form_Load event. In either case,
you'll need to add some code to your email routine and a flag somewhere in
your database. After the Send/Display call, you'll set that flag to True to
indicate that the email has been sent. Before the Send/Display call, you'll
check the value of that flag and only send the email if the flag is False.

Carl Rapson
 
E

EMILYTAN via AccessMonster.com

Great idea!
But can I have the way please?
I want to send it when I open the database.
Thank you
Carl said:
Help!!!!
What is the difference between .Display and .Send? [quoted text clipped - 10 lines]
Set objOutlook = Nothing
End Sub

Display will open the email in a preview window, while Send sends the email
without previewing.

Do you want the email to send automatically when you open the database or
just a specific form? If it's the database, you can set up a macro that
calls your email sub and set that macro to run automatically at startup. If
it's the form, you can put the code in the Form_Load event. In either case,
you'll need to add some code to your email routine and a flag somewhere in
your database. After the Send/Display call, you'll set that flag to True to
indicate that the email has been sent. Before the Send/Display call, you'll
check the value of that flag and only send the email if the flag is False.

Carl Rapson
 
C

Carl Rapson

To have it execute when you open the database, create a macro named AutoExec
and call your sub from that macro. Alternatively, you could create a form
that calls your subroutine in its Form_Load event, and specify that form to
open automatically when the database opens (Tools -> Startup).

Carl Rapson

EMILYTAN via AccessMonster.com said:
Great idea!
But can I have the way please?
I want to send it when I open the database.
Thank you
Carl said:
Help!!!!
What is the difference between .Display and .Send?
[quoted text clipped - 10 lines]
Set objOutlook = Nothing
End Sub

Display will open the email in a preview window, while Send sends the
email
without previewing.

Do you want the email to send automatically when you open the database or
just a specific form? If it's the database, you can set up a macro that
calls your email sub and set that macro to run automatically at startup.
If
it's the form, you can put the code in the Form_Load event. In either
case,
you'll need to add some code to your email routine and a flag somewhere in
your database. After the Send/Display call, you'll set that flag to True
to
indicate that the email has been sent. Before the Send/Display call,
you'll
check the value of that flag and only send the email if the flag is False.

Carl Rapson
 
E

EMILYTAN via AccessMonster.com

What should the action in the macro be?


Carl said:
To have it execute when you open the database, create a macro named AutoExec
and call your sub from that macro. Alternatively, you could create a form
that calls your subroutine in its Form_Load event, and specify that form to
open automatically when the database opens (Tools -> Startup).

Carl Rapson
Great idea!
But can I have the way please?
[quoted text clipped - 24 lines]
 
C

Carl Rapson

To be honest, I'm not certain because I never use macros. You can look in
the online Help for "macro" and it should give you more information. Or, try
posting a question in the Access macros newsgroup where someone with more
knowledge about macros will probably answer.

Carl Rapson

EMILYTAN via AccessMonster.com said:
What should the action in the macro be?


Carl said:
To have it execute when you open the database, create a macro named
AutoExec
and call your sub from that macro. Alternatively, you could create a form
that calls your subroutine in its Form_Load event, and specify that form
to
open automatically when the database opens (Tools -> Startup).

Carl Rapson
Great idea!
But can I have the way please?
[quoted text clipped - 24 lines]
Carl Rapson
 

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