Solved

Close Outlook via Access VBA

Posted on 2008-06-18
6
1,384 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 125 total points
Comment Utility
< 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
Comment Utility
No problem, Matt.  Happens to me too.
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 125 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Outlook Free & Paid Tools
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now