Outlook 2007 SP2 issues

A

alainr

Since I have applied Office 2007 SP2, some of my VBA macros triggered by
rules on incomming mail generate a run-time error. I have reduced the
problem to the following:

1) Create a rule to run a script when a message containing "test" in the
subject arrives (this works fine)

2) The script configured to run is:

Sub TestMapiRule(msgItem As Outlook.MailItem)
Dim objSession As New MAPI.Session
objSession.Logon "", "", False, False, 0 ' Use the existing Outlook
session
MsgBox "test"
objSession.Logoff
Set objSession = Nothing
End Sub

3) When a message arrives and triggers the rule I get the following runtime
error:
Run-time error '-2147417850 (80010106)'
Automation error
Cannot change thread mode after it is set
<End> <Debug>

- The error is triggered by the line "objSession.Logon..." and the
message box never appears.

If I choose the <Debug>, Outlook crashes completely (actually as soon as I
open the VBA editor to attempt any debugging of this issue, Outlook
completely crashes). Selecting <End> kills the script in its tracks and
normal operation of Outlook resumes.

Could anyone with Outlook 2007 SP2 please try to reproduce this issue?

Please let me know if you have observed similar or related issues since
applying OL2007 SP2.

Please let me know if you have any ideas on the possible causes for this
issue.

* Runing Windows XP SP3, all code was running fine before applying SP2 and
nothing was changed just before or after SP2 was applied.
 
A

alainr

I should also add that I have reproduced this issue on two different PCs
(workstation and laptop), both with Office 2007 SP2, on XP SP3
 
A

alainr

I should also add that this issue occurs when mail is received from a POP3
account to be delivered into my default folder's inbox.

Strangely, on one of the PC which also has an Exchange folder, mail received
from exchange also delivered into my default folder's inbox, triggers the
rule and runs through the script just fine wihtout generating a run-time
error.

I suspect there may be an issue with the msgItem object when it is received
specifically from a POP3 account.
 
K

Ken Slovak - [MVP - Outlook]

I can't repro it here with your sample code on Outlook 2007 SP2 running on
Windows XP. I tested and there were no CDO errors at all. No MsgBox
displayed, but there were no errors.

Have you tried registering the CDO.DLL file again?

Also, why use CDO 1.21 at all under Outlook 2007? You can do just about
anything with that object model that you can do with CDO, plus CDO is
heavily secured and will fire security prompts or fire errors when working
with restricted properties or items, the object model won't do that.
 
A

alainr

Thanks for trying the code.

I was using CDO because I had some processes that needed to access
individual MAPI header fields. I wasn't sure if there is a way to map this
ca built-in capabilities without have to do some parsing of text fields (e.g.
parse message headers to extract just the message-ID).

So far I haven't pinpointed the cause to be CDO. However, I will follow
your suggestion and consider modifying my code to avoid the use of CDO, and
instead use the built-in capabilityof of OL2007.

Thanks,
 
A

alainr

I have reduced my issue to the simplest possible case. I think the error I
was getting initially in my original code is related to a more fundamental
problem. I have an Outlook vba module that contains only the following code:

---------------------------------
Sub TestRule(msgItem As Mailitem)
MsgBox "test"
End Sub
---------------------------------

In outlook, I establish a rule that triggers this TestRule() macro (e.g. set
to trigger when subject contains the work "test"). When the rule fires and
the the VBA editor window is not open, I will see a message box saying
"Test". However If I set a breakpoint on the line [msgbox "test"] and
trigger the rule, the rule appears to run fine for about 2 seconds and then
outlook crashes with the following error message:

----------
Microsoft Office Outlook has encountered a problem and needs to close. We
are sorry for the inconvenience.
....
<Debug> <Send Error Report> <Don't Send>
----------

After pressing <Don't Send> Outlook closes (and restarts).

The only references for my projects are:
- Visual Basic For Applications
- Microsoft Outlook 12.0 Object Library
- OLE Automation
- Microsoft Office 12.0 Object Library

The same crash scenario occurs when running outlook in safe mode (Run:
"outlook.exe /safe")

I really think there is a file that got corrupt somewhere. I would like to
try and fix it before I attempt to uninstall/reinstall Office 2007 Ultimate
and related service packs.

At this time I seem to be able to find clunky workarounds the bug by
avoiding certain properties of the Mailitem object in my code and not having
the debugger open when running rules that trigger macros on mail items.

I would be glad to hear any others ideas related to this issue.
 
K

Ken Slovak - [MVP - Outlook]

I cannot reproduce your test scenario at all. Whether the VBA window is
opened or closed and whether or not there's a breakpoint on the MsgBox line
I get no crashes and the rule script macro code runs.

You might want to see if there is any corruption in your Outlook VBA project
file. Close Outlook and find and rename your VbaProject.OTM file to
something like VbaProject.OTM.OLD. Then start Outlook and a new VBA project
file will be created. Try your code in that new VBA project. You will have
to re-link your script macro with the rule.

Another thing to try is to run an Office repair and see if that helps at
all.
 

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