Solved

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

Posted on 2011-02-15
2
383 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Read this checklist to learn more about the 15 things you should never include in an email signature.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

785 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