This is more of a comment than a question. I was unable to find anything about this on the web.
Using Outlook 2007 with Exchange Server 2003 and Windows XP SP3.
Here is a long description, including some background that has nothing to do with VBA but I think is relevant.
As is typical for me, I have an unusual situation. I have some PST files that are encrypted and have passwords. I opened them in Outlook and so every time I start Outlook, Outlook reopens them.
At startup, Outlook asks for the password for each of the PST files. If I type it in, everything is okay.
If I hit ESC instead of entering a password, Outlook proceeds to start normally but if I try to click on the PST folder in the Mail Folders pane, I get the message "The set of folders cannot be opened. The server is not available. Contact your administrator if this condition persists." It does not ask for the password and there is no way to access the folder without closing and restarting Outlook.
Okay, on to VBA: I have some code that runs when a new mail item arrives. It looks through the MAPI stores collection to find the primary Exchange mailbox (ExchangeStoreType = olPrimaryExchangeMailbox). Then it uses the PropertyAccessor to find out whether Out of Office is on or off.
This code worked great for everyone else but intermittently it failed for me with "Run-time error '-2147221231 (800040111)': The server is not available. Contact your administrator if this condition persists." (Obviously, this message is similar to the one Outlook itself gave above.) Sometimes, the message consists of the run-time error and "Automation error" without the explanation.
Debugging the code, I found that when the loop hit a store corresponding to one of the password-protected PST files and I didn't enter the password when Outlook started, the code failed when trying to create an instance of the store:
So the solution was to put the classic
in the function. But I also had to modify the loop to use an index because there is no way to get it to assign the "next" next store when it can't assign the "current" next store:
So this post is largely to document the existence of this problem. If you coded it the way it was originally ("For Each ..."), using "On Error Resume Next," then the code would simply fail to function intermittently and silently.
If anyone has any additional advice, that would be great.
Using Outlook 2007 with Exchange Server 2003 and Windows XP SP3.
Here is a long description, including some background that has nothing to do with VBA but I think is relevant.
As is typical for me, I have an unusual situation. I have some PST files that are encrypted and have passwords. I opened them in Outlook and so every time I start Outlook, Outlook reopens them.
At startup, Outlook asks for the password for each of the PST files. If I type it in, everything is okay.
If I hit ESC instead of entering a password, Outlook proceeds to start normally but if I try to click on the PST folder in the Mail Folders pane, I get the message "The set of folders cannot be opened. The server is not available. Contact your administrator if this condition persists." It does not ask for the password and there is no way to access the folder without closing and restarting Outlook.
Okay, on to VBA: I have some code that runs when a new mail item arrives. It looks through the MAPI stores collection to find the primary Exchange mailbox (ExchangeStoreType = olPrimaryExchangeMailbox). Then it uses the PropertyAccessor to find out whether Out of Office is on or off.
This code worked great for everyone else but intermittently it failed for me with "Run-time error '-2147221231 (800040111)': The server is not available. Contact your administrator if this condition persists." (Obviously, this message is similar to the one Outlook itself gave above.) Sometimes, the message consists of the run-time error and "Automation error" without the explanation.
Debugging the code, I found that when the loop hit a store corresponding to one of the password-protected PST files and I didn't enter the password when Outlook started, the code failed when trying to create an instance of the store:
Code:
For Each myStore in theStores '<-- Failed here...
...
Next myStore '<-- ... or failed here, depending on the way the stores were ordered
Code:
On Error Resume Next
Code:
For i=1 to theStores.Count
Set myStore = theStores.Item(i)
...
Next i
If anyone has any additional advice, that would be great.