You need to declare a MailItem variable using the WithEvents statement to
hook into user or application driven events, such as sending the e-mail.
Dim objOutlook As Outlook.Application
Dim WithEvents objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
.To = em
.Subject = stext
.Body = mtext
.Display
End With
Then you can use this event to determine if the e-mail was sent or not:
Private Sub objOutlookMsg_Send(Cancel As Boolean)
'Your code here
End Sub
--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog:
http://blogs.officezealot.com/legault/
"DEI" wrote:
> I am using the following code to automate an email message from Access. I
> would like to automatically update fields on a form in Access witha time
> stamp to confirm when the message was sent. I would also like the email
> message to display before it is sent.
>
> I can easily make the form in Access update automatically, however, it will
> be possible for the user to cancel the message, in which case the form should
> not be stamped because no message ws sent. Unfortunately, though, when I
> create the email message in the code, the code keeps running. I am basically
> looking for the best place, or best way to evaluate that a message was sent.
> So that if the user cancels the message, then the form does not update.
>
> Is there any way to halt execution? Or pause before the user either sends or
> aborts the message?
>
> Dim objOutlook As Outlook.Application
> Dim objOutlookMsg As Outlook.MailItem
> Dim objOutlookRecip As Outlook.Recipient
>
> Set objOutlook = CreateObject("Outlook.Application")
> Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
>
> With objOutlookMsg
>
> .To = em
> .Subject = stext
> .Body = mtext
> .Display
>
> End With