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?
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?