"Unable to open the Outlook Window" 
Author Message
 "Unable to open the Outlook Window"

Hi

I've got an Access app. which has to start Outlook, log on
to a mailbox then iterate through items in one of its
folders, saving & reading attachments, then replying to
each of the mail items. On completion, I drop all of the
Outlook references (folders, items, attachments etc) then
log-off and quit Outlook.

Here's the problem:

After running the process some of the users get the
following error when trying to re-start Outlook:
"Unable to open the Outlook window. The server is not
available. Contact your administrator if this condition
persists."

It seems that despite dropping all Outlook references
(yes, all!), the application is sometimes leaving
Outlook.exe running. If the users log off (the PC) then
log on again, the problem is solved.

Can anyone help with a better fix than that???



Sat, 09 Jul 2005 20:21:06 GMT  
 "Unable to open the Outlook Window"
Post the code you are using to release all your Outlook objects.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm


Quote:
> Hi

> I've got an Access app. which has to start Outlook, log on
> to a mailbox then iterate through items in one of its
> folders, saving & reading attachments, then replying to
> each of the mail items. On completion, I drop all of the
> Outlook references (folders, items, attachments etc) then
> log-off and quit Outlook.

> Here's the problem:

> After running the process some of the users get the
> following error when trying to re-start Outlook:
> "Unable to open the Outlook window. The server is not
> available. Contact your administrator if this condition
> persists."

> It seems that despite dropping all Outlook references
> (yes, all!), the application is sometimes leaving
> Outlook.exe running. If the users log off (the PC) then
> log on again, the problem is solved.

> Can anyone help with a better fix than that???



Sat, 09 Jul 2005 22:12:36 GMT  
 "Unable to open the Outlook Window"
Thnaks for the reply Ken.

Here's the bare bones of the code, sorry it's so long!:

' Declare objects
    Public oOutlookApp As Outlook.Application
    Public oNamespace As Outlook.NameSpace
    Public oFolder As Outlook.mapiFolder
    Public oItems As Outlook.Items
    Public oItem As Object

Function gfbUnpack() as Boolean

' Create MAPI session:
    Set oOutlookApp = GetObject(, "Outlook.Application")
    Set oNamespace = oOutlookApp.GetNamespace("MAPI")
    oNamespace.Logon gstrProfile, , False, True

' Reference the required folder:    
    Set oFolder = oNamespace.GetDefaultFolder
(olFolderInbox).Parent.Folders(gstrFolder)
    Set oItems = oFolder.Items

' Count the items in the folder:

' Loop through items in the required folder:
    For ' ~ Each item in the folder

        ' Code which opens & validates attachments here

        ' Call sub-routine which builds & sends reply:
        gfbAcknowledge oItem

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Call to sub routine inserted here for illustration only
Function gfbAcknowledge(aoItem As Object)

    Dim oAttachments As Outlook.Attachments
    Dim oReply As Outlook.MailItem

' Create reply object:
    Set oReply = aoItem.Reply

' Code which builds mail body/attachments etc here . . .

    Set oAttachments = oReply.Attachments
    oAttachments.Add gstrXLVHDErrors, , Len(strBody) + 1

    ' Build and send the acknowledgement:
    oReply.Body = strBody & vbCrLf & oReply.Body
    oReply.Send

' Release memory:
    Set oReply = Nothing
    Set oAttachments = Nothing

Exit Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Next ' folder item

' Release memory:
    Set oItem = Nothing
    Set oItems = Nothing
    Set oFolder = Nothing
    oNamespace.Logoff
    Set oNamespace = Nothing
    oOutlookApp.Quit
    Set oOutlookApp = Nothing

Exit Function

Quote:
>-----Original Message-----
>Post the code you are using to release all your Outlook
objects.

>--
>Ken Slovak
>[MVP - Outlook]
>http://www.slovaktech.com
>Lead Author, Professional Outlook 2000 Programming, Wrox
Press
>Lead Author, Beginning VB 6 Application Development, Wrox
Press
>Attachment Options
>http://www.slovaktech.com/attachmentoptions.htm
>Extended Reminders
>http://www.slovaktech.com/extendedreminders.htm



>> Hi

>> I've got an Access app. which has to start Outlook, log
on
>> to a mailbox then iterate through items in one of its
>> folders, saving & reading attachments, then replying to
>> each of the mail items. On completion, I drop all of the
>> Outlook references (folders, items, attachments etc)
then
>> log-off and quit Outlook.

>> Here's the problem:

>> After running the process some of the users get the
>> following error when trying to re-start Outlook:
>> "Unable to open the Outlook window. The server is not
>> available. Contact your administrator if this condition
>> persists."

>> It seems that despite dropping all Outlook references
>> (yes, all!), the application is sometimes leaving
>> Outlook.exe running. If the users log off (the PC) then
>> log on again, the problem is solved.

>> Can anyone help with a better fix than that???

>.



Sun, 10 Jul 2005 17:02:08 GMT  
 "Unable to open the Outlook Window"
It certainly looks like you are releasing everything, can you verify
that your release code is being executed? The only thing I see is that
you are using GetObject, which will fail if Outlook is not already
running. Since Outlook would already be running, you wouldn't need to
log on to the NameSpace object, and if the user's Outlook is already
running you might not want to use the Application.Quit method to close
it when your code is finished.

The other question is whether you are handling all errors and if you
are getting any errors when running your code.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm


Quote:
> Thnaks for the reply Ken.

> Here's the bare bones of the code, sorry it's so long!:

> ' Declare objects
>     Public oOutlookApp As Outlook.Application
>     Public oNamespace As Outlook.NameSpace
>     Public oFolder As Outlook.mapiFolder
>     Public oItems As Outlook.Items
>     Public oItem As Object

> Function gfbUnpack() as Boolean

> ' Create MAPI session:
>     Set oOutlookApp = GetObject(, "Outlook.Application")
>     Set oNamespace = oOutlookApp.GetNamespace("MAPI")
>     oNamespace.Logon gstrProfile, , False, True

> ' Reference the required folder:
>     Set oFolder = oNamespace.GetDefaultFolder
> (olFolderInbox).Parent.Folders(gstrFolder)
>     Set oItems = oFolder.Items

> ' Count the items in the folder:

> ' Loop through items in the required folder:
>     For ' ~ Each item in the folder

> ' Code which opens & validates attachments here

> ' Call sub-routine which builds & sends reply:
> gfbAcknowledge oItem

> '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
> ' Call to sub routine inserted here for illustration only
> Function gfbAcknowledge(aoItem As Object)

>     Dim oAttachments As Outlook.Attachments
>     Dim oReply As Outlook.MailItem

> ' Create reply object:
>     Set oReply = aoItem.Reply

> ' Code which builds mail body/attachments etc here . . .

>     Set oAttachments = oReply.Attachments
>     oAttachments.Add gstrXLVHDErrors, , Len(strBody) + 1

>     ' Build and send the acknowledgement:
>     oReply.Body = strBody & vbCrLf & oReply.Body
>     oReply.Send

> ' Release memory:
>     Set oReply = Nothing
>     Set oAttachments = Nothing

> Exit Function
> '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

>     Next ' folder item

> ' Release memory:
>     Set oItem = Nothing
>     Set oItems = Nothing
>     Set oFolder = Nothing
>     oNamespace.Logoff
>     Set oNamespace = Nothing
>     oOutlookApp.Quit
>     Set oOutlookApp = Nothing

> Exit Function



Sun, 10 Jul 2005 22:24:08 GMT  
 "Unable to open the Outlook Window"

Yes, I know the code is running. Even if it were to hit
the error handler, I still 'clean-up' afterwards.

Regarding GetObject, I test to see if the user is logged
on to the correct account, and use CreateObject/GetObject
as required. I've attached that bit of code below. Even
they are already logged on, I still use .LoggOff & .Quit
at the end -you'll see I set a 'created' flag, but it's
not used :( . Maybe if I left Outlook open & let the users
quit, the problem would go away?

It seems the error is returned about 25% of the times it's
used. I will try and establish if it relates to them
already being logged on to Outlook or not.

I appreciate your help, Ken.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Ascertain whether Outlook is already running:
    On Error Resume Next
    Set oOutlookApp = GetObject(, "Outlook.Application")
    lngErr = Err.Number
    On Error GoTo Err_gfbytOutlookLogon

    If lngErr = 0 Then ' Outlook is already running
        Set oNamespace = oOutlookApp.GetNamespace("MAPI")
        ' Check if user is already logged on to correct
account:
        If oNamespace.CurrentUser <> gstrMailbox Then '
Not logged on to correct account
            gfbytOutlookLogon = 1
            Set oOutlookApp = Nothing
            Exit Function
        End If
    Else ' Outlook is not running, so create a new
instance:
        Set oOutlookApp = CreateObject
("Outlook.Application")
        Set oNamespace = oOutlookApp.GetNamespace("MAPI")
        ' Log on to the appropriate mailbox:
        oNamespace.Logon gstrProfile, , False, True
        blnCreatedOutlookInstance = True
    End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Quote:
>-----Original Message-----
>It certainly looks like you are releasing everything, can
you verify
>that your release code is being executed? The only thing
I see is that
>you are using GetObject, which will fail if Outlook is
not already
>running. Since Outlook would already be running, you
wouldn't need to
>log on to the NameSpace object, and if the user's Outlook
is already
>running you might not want to use the Application.Quit
method to close
>it when your code is finished.

>The other question is whether you are handling all errors
and if you
>are getting any errors when running your code.

>--
>Ken Slovak
>[MVP - Outlook]
>http://www.slovaktech.com
>Lead Author, Professional Outlook 2000 Programming, Wrox
Press
>Lead Author, Beginning VB 6 Application Development, Wrox
Press
>Attachment Options
>http://www.slovaktech.com/attachmentoptions.htm
>Extended Reminders
>http://www.slovaktech.com/extendedreminders.htm



>> Thnaks for the reply Ken.

>> Here's the bare bones of the code, sorry it's so long!:

>> ' Declare objects
>>     Public oOutlookApp As Outlook.Application
>>     Public oNamespace As Outlook.NameSpace
>>     Public oFolder As Outlook.mapiFolder
>>     Public oItems As Outlook.Items
>>     Public oItem As Object

>> Function gfbUnpack() as Boolean

>> ' Create MAPI session:
>>     Set oOutlookApp = GetObject(, "Outlook.Application")
>>     Set oNamespace = oOutlookApp.GetNamespace("MAPI")
>>     oNamespace.Logon gstrProfile, , False, True

>> ' Reference the required folder:
>>     Set oFolder = oNamespace.GetDefaultFolder
>> (olFolderInbox).Parent.Folders(gstrFolder)
>>     Set oItems = oFolder.Items

>> ' Count the items in the folder:

>> ' Loop through items in the required folder:
>>     For ' ~ Each item in the folder

>> ' Code which opens & validates attachments here

>> ' Call sub-routine which builds & sends reply:
>> gfbAcknowledge oItem

>> ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''
>> ' Call to sub routine inserted here for illustration
only
>> Function gfbAcknowledge(aoItem As Object)

>>     Dim oAttachments As Outlook.Attachments
>>     Dim oReply As Outlook.MailItem

>> ' Create reply object:
>>     Set oReply = aoItem.Reply

>> ' Code which builds mail body/attachments etc here . . .

>>     Set oAttachments = oReply.Attachments
>>     oAttachments.Add gstrXLVHDErrors, , Len(strBody) + 1

>>     ' Build and send the acknowledgement:
>>     oReply.Body = strBody & vbCrLf & oReply.Body
>>     oReply.Send

>> ' Release memory:
>>     Set oReply = Nothing
>>     Set oAttachments = Nothing

>> Exit Function
>> ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''

>>     Next ' folder item

>> ' Release memory:
>>     Set oItem = Nothing
>>     Set oItems = Nothing
>>     Set oFolder = Nothing
>>     oNamespace.Logoff
>>     Set oNamespace = Nothing
>>     oOutlookApp.Quit
>>     Set oOutlookApp = Nothing

>> Exit Function

>.



Mon, 11 Jul 2005 23:32:01 GMT  
 "Unable to open the Outlook Window"
I'd step the code on a setup that has the problem and make sure all
your code is being executed as intended. I'd also set a breakpoint at
the end of the code and test for Is Nothing on all the objects to make
sure they are released.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm


Quote:

> Yes, I know the code is running. Even if it were to hit
> the error handler, I still 'clean-up' afterwards.

> Regarding GetObject, I test to see if the user is logged
> on to the correct account, and use CreateObject/GetObject
> as required. I've attached that bit of code below. Even
> they are already logged on, I still use .LoggOff & .Quit
> at the end -you'll see I set a 'created' flag, but it's
> not used :( . Maybe if I left Outlook open & let the users
> quit, the problem would go away?

> It seems the error is returned about 25% of the times it's
> used. I will try and establish if it relates to them
> already being logged on to Outlook or not.

> I appreciate your help, Ken.

> ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
> ' Ascertain whether Outlook is already running:
>     On Error Resume Next
>     Set oOutlookApp = GetObject(, "Outlook.Application")
>     lngErr = Err.Number
>     On Error GoTo Err_gfbytOutlookLogon

>     If lngErr = 0 Then ' Outlook is already running
>         Set oNamespace = oOutlookApp.GetNamespace("MAPI")
>         ' Check if user is already logged on to correct
> account:
>         If oNamespace.CurrentUser <> gstrMailbox Then '
> Not logged on to correct account
>             gfbytOutlookLogon = 1
>             Set oOutlookApp = Nothing
>             Exit Function
>         End If
>     Else ' Outlook is not running, so create a new
> instance:
>         Set oOutlookApp = CreateObject
> ("Outlook.Application")
>         Set oNamespace = oOutlookApp.GetNamespace("MAPI")
>         ' Log on to the appropriate mailbox:
>         oNamespace.Logon gstrProfile, , False, True
>         blnCreatedOutlookInstance = True
>     End If
> ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



Tue, 12 Jul 2005 23:21:35 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Crystal Reports "Unable to open database"

2. Crystal Report "unable to open database"

3. "Windows was unable to write ..."

4. Problem With "window.showmodaldialog("")"

5. Trapping "Expand", "Open", "Explore" in Windows Explorer?

6. "FileProperties" window when opening a template

7. window.open - "Object required"

8. Using windows "Open" dialogue boxes

9. Error by "Open Window"

10. capture "open in new window"

11. "Open/Open With..." from Win Explorer

12. "Currently Unable to Quit Access" Error

 

 
Powered by phpBB® Forum Software