Solved

Handling an instance of outlook

Posted on 2002-03-06
3
169 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 51

Expert Comment

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

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hide vba in gp 7 116
Modifying Conditional Format from VBA code 3 71
clicking a shape in a frame array vb6 3 48
Access2016 ignore hyphen in data entry or searches 5 47
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 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