Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Close Outlook via Access VBA

Posted on 2008-06-18
6
Medium Priority
?
1,408 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 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
Technology Partners: 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!

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

636 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