Solved

Close Outlook via Access VBA

Posted on 2008-06-18
6
1,388 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
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 7 Professional 6 61
is Microsoft Access going to Die? 9 50
Display <> "Yes" records 10 10
Combo Box with a control source is "locked" 10 9
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

777 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