?
Solved

Handling an instance of outlook

Posted on 2002-03-06
3
Medium Priority
?
172 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 600 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 53

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 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