Solved

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

Posted on 2011-02-15
2
386 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
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.
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…

695 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