Solved

Access vba - determine if a outlook email created is still open

Posted on 2011-02-15
2
381 Views
Last Modified: 2012-06-22
Currently create an outlook email in access and open to allow changes and review before sending.

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(0)
With objOutlookMsg
    .To = varTo
    .Subject = strSubject
    .HTMLBody = strBody
    .mileage = intID
    .Display
Set objOutlook = Nothing
Set objOutlookMsg = Nothing


At this stage email not saved in drafts and I would prefer not to so user can just cancel email if they don't want it.

If user sends email I am reading the email by looking it up in outlook and updating the database with email info - this all works fine. This is done when user exits form that created email.

Issue is that the user might leave email open and exit form before they send.

I would like to pick up that the email is still open on the screen when exiting form. (and then I'l look for it again later.)

Is there a way to check email that is open on screen and loop through then - this email is not actually stored in outlook yet. (I am recording a unique ID for each email created in the Mileage field so I can identify the email easy enough - its just how to get to it)

0
Comment
Question by:donhannam
2 Comments
 
LVL 19

Accepted Solution

by:
darbid73 earned 500 total points
ID: 34904313
There are a couple of ways you could do that.  One way could be to check if the inspector window - which is the name of the window that an email is in has been closed.  But this would be complicated.

My preferred method is as follows.

You need to follow the events of the email.

At the top of your form you need

Private WithEvents objOutlookMsg As Outlook.MailItem

Open in new window


Once you do this the VB Editor will show you all the events that are available for this.


Private Sub objOutlookMsg_Close(Cancel As Boolean)
On Error GoTo Err_objOutlookMsg_Close

msgbox "This email was closed

set objOutlookMsg = nothing


Exit_objOutlookMsg_Close:
    Exit Sub

Err_objOutlookMsg_Close:
    MsgBox "objOutlookMsg_Close - " & Err.Description
    Resume Exit_objOutlookMsg_Close
End Sub

Open in new window


It is very important for Outlook that you get rid of all objects otherwise Outlook will fail to close properly.
0
 

Author Closing Comment

by:donhannam
ID: 34911929
Thanks darbid73 this worked great
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Create high volume marketing opportunities using email signatures with these top 10 DOs and DON'Ts of email signature marketing.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now