[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Close Outlook via Access VBA

Posted on 2008-06-18
6
Medium Priority
?
1,412 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 375 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 375 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 375 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 375 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

873 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