Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
outlook 365 3 59
Windows 7 Domain User Loses Credentials Every Night 9 47
Outlook 2016 processing loop 4 49
PDF File freezes when printing 20 31
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

737 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