Solved

Close Outlook via Access VBA

Posted on 2008-06-18
6
1,395 Views
Last Modified: 2013-11-27
How can I close Outlook by using VBA code?  My RDC users are opening multiple instances of Outlook and that is causing problems/confusion.  I'd like to be able, upon opening a new Access form, to check to see if Outlook is open, and if it is, prevent another instance from opening.  If Outlook is not open, open it.

Best regards,
 
Rick Farris

[contact info deleted -- modus_operandi, EE Moderator]
0
Comment
Question by:rhfarris
[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
6 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 125 total points
ID: 21812541
Hi, rhfarris.

You'll need something like the code below.  GetObject attempts to attach to an open Outlook session.  If there is one, then Err.Number will return 0.  If there isn't one, then Err.Number will return the error number which will be greater than 0.
Dim olkApp
On Error Resume Next
Set olkApp = GetObject(,"Outlook.Application")
If Err.Number > 0 Then
    'Outlook is not open so open it
Else
    'Outlook is already open
End If
Set olkApp = Nothing

Open in new window

0
 
LVL 35

Assisted Solution

by:mvidas
mvidas earned 125 total points
ID: 21812580
Hi Rick,

How is your code doing it currently?  If you use the CreateObject function with outlook.application, it will either assign the currently open outlook to the variable, or create a new one if it doesn't exist.

Matt
 Dim olApp As Object 'you could also use Outlook.Application'
 Set olApp = CreateObject("outlook.application")
 'olApp now refers to the already-opened application if it existed, _
  or creates a new one if it did not exist'

Open in new window

0
 
LVL 35

Expert Comment

by:mvidas
ID: 21812601
Sorry BDF, I need to start refreshing again before posting :) Slightly different methods, but I don't like to impede on questions with responses.
Matt
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 125 total points
ID: 21812877
< How can I close Outlook by using VBA code?  My RDC users are opening multiple instances of Outlook and that is causing problems/confusion.>



    Dim oOutlook As Object
    Dim oNameSpace As Object
    Dim oInbox As Object
     
    Set oOutlook = CreateObject("Outlook.Application")
    Set oNameSpace = oOutlook.GetNamespace("MAPI")
    Set oInbox = oNameSpace.Folders(1)
     
    oOutlook.Quit  '<<< will close all open outlook

    Set oInbox = oInbox.Folders("Inbox")       'open a new one
    oInbox.Display
0
 
LVL 76

Expert Comment

by:David Lee
ID: 21813092
No problem, Matt.  Happens to me too.
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 125 total points
ID: 21819663
rhfarris,

Just a note here.

Whatever method you use, just do a quick check in the Task Manager to see if OUTLOOK.EXE is still running or not.
Sometime the Application Objects get left in memory.

JeffCoachman
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
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.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
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…

696 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