Solved

Handling an instance of outlook

Posted on 2002-03-06
3
171 Views
Last Modified: 2010-05-02
I have a form which loads an instance of outlook.

When the form is closed I quit the instance.

It all works fine but what I would like is some way of checking whether the user has outlook open when I load the form and then act accrdingly when I close the form.

At present my code unloads outlook regardless of its state when the form loaded

i.e

Function InitOutlook() As Integer

On Error Resume Next

InitOutlook = False

statBar.Panels(1).Text = "Creating Outlook application link...."
Set appOut = CreateObject("Outlook.Application")
If appOut Is Nothing Then
  Set appOut = New Outlook.Application
End If
statBar.Panels(1).Text = ""

If appOut Is Nothing Then
  MsgBox "Error instantiating outlook" & Err.Description
  Exit Function
End If

statBar.Panels(1).Text = "Creating Outlook Namespace...."
Set mNS = appOut.GetNamespace("MAPI")
If Err Then
   MsgBox "Error creating NameSpace " & Err.Description
   Exit Function
End If

statBar.Panels(1).Text = ""
InitOutlook = True

End Function

Then on unload

set mNS = nothing
appout.quit
set appout = nothing
0
Comment
Question by:colindow
[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
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 150 total points
ID: 6844661
on Error Resume Next

init = true
set appOut = GetObject(, "Outlook.Application")
if err.number <> 0 then
   init = false
   Set appOut = CreateObject("Outlook.Application")
end if




0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6844689
or alternatively you can search for the window using findwindow api

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

if findwindow(vbnullstring, "Outlook") > 0 then
   init = true
else
   init = false
end if
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 6846037
Agree with bobbit31 that using GetObject to see whether an Object instance is opened.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

691 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