Solved

Handling an instance of outlook

Posted on 2002-03-06
3
168 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
  • 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 50

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 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