Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-02-15
2
Medium Priority
?
390 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 20

Accepted Solution

by:
darbid73 earned 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
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…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

876 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