Outlook Automation, Office 2007

  • Thread starter Dale_Fye via AccessMonster.com
  • Start date
D

Dale_Fye via AccessMonster.com

I'm working on an application and have a need to send a couple of
notification emails from within the application, with attachments (so
SendObject is out).

I've found some code and it is working, but not precisly as I would like.
What I want to do is identify whether Outlook was open when I entered the
function, so that when I exit the function, I can close it if it was not open.


Unfortunately, the code segment below is not functioning the way I would
expect. My expectation is that if Outlook is already open, then the 2nd line
(GetObject) will not generate an error, but if Outlook is closed, it will
generate an error, the response to which is to use CreateObject to open an
instance of Outlook.

On Error Resume Next
Set myObject = GetObject("", "Outlook.Application")
If Err.Number = 0 Then
bOutlookOpenAtStart = True
Else
Set myObject = CreateObject("Outlook.Application")
bOutlookOpenAtStart = False
End If

However, when I run this code, Access is opening Outlook on the GetObject
line (even if it is not already open). I've confirmed this by running the
WindowsTaskManager and observing Processes window as I step through the code.

I've got the code working to close Outlook at the end of my function, but
since the GetObject is not generating an error, bOutlookOpenAtStart is always
True, so the app never closes Outlook, unless I manually move the cursor to
those lines while debugging.

Any ideas?
 
P

Piet Linden

I'm working on an application and have a need to send a couple of
notification emails from within the application, with attachments (so
SendObject is out).

I've found some code and it is working, but not precisly as I would like.
What I want to do is identify whether Outlook was open when I entered the
function, so that when I exit the function, I can close it if it was not open.

Unfortunately, the code segment below is not functioning the way I would
expect.  My expectation is that if Outlook is already open, then the 2nd line
(GetObject) will not generate an error, but if Outlook is closed, it will
generate an error, the response to which is to use CreateObject to open an
instance of Outlook.

    On Error Resume Next
    Set myObject = GetObject("", "Outlook.Application")
    If Err.Number = 0 Then
        bOutlookOpenAtStart = True
    Else
        Set myObject = CreateObject("Outlook.Application")
        bOutlookOpenAtStart = False
    End If

However, when I run this code, Access is opening Outlook on the GetObject
line (even if it is not already open).  I've confirmed this by running the
WindowsTaskManager and observing Processes window as I step through the code.

I've got the code working to close Outlook at the end of my function, but
since the GetObject is not generating an error, bOutlookOpenAtStart is always
True, so the app never closes Outlook, unless I manually move the cursor to
those lines while debugging.

Any ideas?

--
HTH

Dale Fye

http://www.accessmonster.com/Uwe/Forums.aspx/access-modules/200906/1

You need fIsAppRunning() from Access web.
http://www.mvps.org/access/api/api0007.htm

Here's a link to an example of using it in your code...
http://www.mvps.org/access/modules/mdl0006.htm
 
D

Dale_Fye via AccessMonster.com

Piet,

That looks great, and I'll use it.

However, what I'm really interested in is why Access is opening Outlook when
I use GetObject, if it is not already open. This is not the way it has
worked in the past (2000, 2003).

Dale

Piet said:
I'm working on an application and have a need to send a couple of
notification emails from within the application, with attachments (so
[quoted text clipped - 36 lines]

You need fIsAppRunning() from Access web.
http://www.mvps.org/access/api/api0007.htm

Here's a link to an example of using it in your code...
http://www.mvps.org/access/modules/mdl0006.htm
 
S

Stewart Berman

Dale_Fye via AccessMonster.com said:
Piet,

That looks great, and I'll use it.

However, what I'm really interested in is why Access is opening Outlook when
I use GetObject, if it is not already open. This is not the way it has
worked in the past (2000, 2003).

This is Microsoft -- The past is not prolog.
Dale

Piet said:
I'm working on an application and have a need to send a couple of
notification emails from within the application, with attachments (so
[quoted text clipped - 36 lines]

You need fIsAppRunning() from Access web.
http://www.mvps.org/access/api/api0007.htm

Here's a link to an example of using it in your code...
http://www.mvps.org/access/modules/mdl0006.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top