Has anyone seen an instance where On Error Resume Next was NOT successful in
suppressing a run-time error?
I have an application which uses Automation to control Word and Excel. It's
tricky because we need to support Office 2000, XP, 2003 and 2007. Obviously,
within our code one of the first things we do is determine the version so
that we know which functions are or are not available. However, beyond that,
compilation is tricky as well since we need to ensure that in the IDE we
reference the Word9 and Excel9 object libraries, in order to pick up the
lowest common denominator interface at compile time, which will support any
version of the corresponding interfaces found on the box at run-time.
Anyway, one of our build boxes got messed up and our application was
compiled against the Office 2003 interfaces. We picked up the problem during
testing on an XP environment since the application threw an untrapped error
up to the calling method: Automation error;The object invoked has
disconnected from its clients. We spent quite a while tracking down the
problem, finally resolved it to the incorrectly configured build platform,
fixed it, recompiled and the application works fine.
Which is why I can't justify spending a whole lot of additional effort on
this, but we picked up something very strange during our debugging, which I
have not seen in over a decade of VB6 development.
On Error Resume Next ' First try the more sophisticated open syntax
PostEvent C_LIB, C_CLASS, "zViewWordDoc", srsEvtInfo, "Before
m_AppWord.Documents.Open(" & m_Document & ")"
Set m_DocWord = m_AppWord.Documents.Open(CStr(m_Document), False, True,
False)
PostEvent C_LIB, C_CLASS, "zViewWordDoc", srsEvtInfo, "Just After
m_AppWord.Documents.Open(" & m_Document & ")"
We know the error occured on the Set statment, since we received the first
PostEvent message, but not the second. What we can't figure out is, with a
covering On Error Resume Next in effect, how an automation error would cause
an untrapped error to be thrown up to the calling method. The whole purpose
of the On Error Resume Next in this context is to first attempt an Open
operation which is supported by Office 2000 and higher. If that operation
fails then we attempt a different Open operation which is backward
compatible with XP/2000. And this error suppression works well. But for some
reason, the Automation error;The object invoked has disconnected from its
clients, does not get suppressed by the On Error Resume Next. Is there an
explanation for this behavior?
Thanks for your advice!
Joseph Geretz
MikeD - 06 Jun 2008 19:33 GMT
> Has anyone seen an instance where On Error Resume Next was NOT successful in suppressing a run-time error?
Very first thing to check...
Display VB's Options dialog and go to the General tab. Make sure Error Trapping is NOT set to Break on All Errors. If your code is
in a .cls file, then also make sure it's not set to Break in Class Module. IMO, the best *default* setting is Break on Unhandled
Errors. If you only want to change this setting temporarily, then you should change it from the Toggle context menu of a code window
rather than in the Options dialog box.

Signature
Mike
Microsoft Visual Basic MVP
-mhd - 06 Jun 2008 21:34 GMT
>> Has anyone seen an instance where On Error Resume Next was NOT successful in suppressing a run-time error?
>
[quoted text clipped - 4 lines]
>Errors. If you only want to change this setting temporarily, then you should change it from the Toggle context menu of a code window
>rather than in the Options dialog box.
Did the error even come from the VB app or did the object you are
automating through com throw the error?
-mhd
Joseph Geretz - 06 Jun 2008 22:05 GMT
Thanks guys for the responses.
This error is an error which was occurring at run time.
MikeD, as far as I understand VB error handling, the Error Trapping
properties which you cite are only relevant for code which is running within
the IDE. Are you saying that these properties can change Error Trapping
behavior in the runtime App?
MHD, it seems as though the error emanated from within VB; that is the line
Set m_DocWord = m_AppWord.Documents.Open(CStr(m_Document), False, True,
False)
Failed to execute because the object m_AppWord had disconnected from its
clients.
But again, why would that matter? Let's say m_Appword.Documents.Open()
encountered an untrapped error internally. The main point which I cannot
understand is that with On Error Resume Next in effect, why would an error
on that line of code throw an untrapped error up to the calling method?
Thanks for your advice,
Joseph Geretz
"MikeD" <nobody@nowhere.edu> wrote:
>> Has anyone seen an instance where On Error Resume Next was NOT successful
>> in suppressing a run-time error?
[quoted text clipped - 8 lines]
>should change it from the Toggle context menu of a code window
>rather than in the Options dialog box.
Did the error even come from the VB app or did the object you are
automating through com throw the error?
-mhd