On Error routine NOT "Firing"

B

Bill

In an earlier post exchange with Douglas Steele,
I implemented an On Error routine to deal with
errors raised by the use of Screen.ActiveForm,
Screen.ActiveReport and Screen.ActiveControl
when screen displays were inappropriate for one
or the other.

My problem is that my error routine IS NOT
getting control when the error condition is
encountered at runtime.

From my earlier indirectly related thread, my
code:

Option Compare Database

Public Function HTMLctxHelp()
'====================================================================================
' AutoKeys macro is coded to intercept the user's use of program function
key "F1".
' This function accesses the context ID for whatever is currently on the
screen and
' launches the HTML viewer that will "autosync" the topic with the current
display.
'====================================================================================
Dim CtlCtxID As Long
Dim FrmCtxID As Long
Dim RptCtxID As Long
Dim ID As Long
Dim strHelpPath As String

On Error GoTo ExpectedScreenError

'====================================================================================
' Only 1 of the 3 "Screen" statements will return a value. Other two will
each raise
' an error, leaving the target variables zero.
'====================================================================================
RptCtxID = Screen.ActiveReport.HelpContextId
CtlCtxID = Screen.ActiveControl.HelpContextId
FrmCtxID = Screen.ActiveControl.HelpContextId

ID = CtlCtxID + RptCtxID + FrmCtxID 'x+0+0, 0+x+0, 0+0+x or 0+0+0
If ID = 0 Then ID = 9999 'No ID specified, show TOC @
"Welcome"


strHelpPath = IPPath & "\TMS.chm"

Call HtmlHelpCtx(strHelpPath, ID)


End_HTMLctxHelp:
Exit Function

ExpectedScreenError:
'====================================================================================
' Two of the three "Screen" method statements will raise an error condition
because
' there will only be control elements for whatever type of screen is
currently open,
' be it a report, form or other control.
'====================================================================================
If Err.Number = 2474 Then 'In fact a screen error? (Steele thought it
was 2476?)
Resume Next 'Yes, we'll ignore it
Else
MsgBox Err.Number & ": " & Err.Description, vbOKOnly + vbCritical
Resume End_HTMLctxHelp
End If

End Function


With a "Report" in currently displayed in preview,
error 2474 is raised for the Screen.ActiveControl,
but the error routine DOES NOT get control.
 
D

Dirk Goldgar

Bill said:
In an earlier post exchange with Douglas Steele,
I implemented an On Error routine to deal with
errors raised by the use of Screen.ActiveForm,
Screen.ActiveReport and Screen.ActiveControl
when screen displays were inappropriate for one
or the other.

My problem is that my error routine IS NOT
getting control when the error condition is
encountered at runtime.

From my earlier indirectly related thread, my
code:

Option Compare Database

Public Function HTMLctxHelp()
'=======================================================================
=============
' AutoKeys macro is coded to intercept the user's use of program
function key "F1".
' This function accesses the context ID for whatever is currently on
the screen and
' launches the HTML viewer that will "autosync" the topic with the
current display.
'=======================================================================
=============
Dim CtlCtxID As Long
Dim FrmCtxID As Long
Dim RptCtxID As Long
Dim ID As Long
Dim strHelpPath As String

On Error GoTo ExpectedScreenError

'=======================================================================
=============
' Only 1 of the 3 "Screen" statements will return a value. Other two
will each raise
' an error, leaving the target variables zero.
'=======================================================================
=============
RptCtxID = Screen.ActiveReport.HelpContextId
CtlCtxID = Screen.ActiveControl.HelpContextId
FrmCtxID = Screen.ActiveControl.HelpContextId

ID = CtlCtxID + RptCtxID + FrmCtxID 'x+0+0, 0+x+0, 0+0+x or
0+0+0 If ID = 0 Then ID = 9999 'No ID specified,
show TOC @ "Welcome"


strHelpPath = IPPath & "\TMS.chm"

Call HtmlHelpCtx(strHelpPath, ID)


End_HTMLctxHelp:
Exit Function

ExpectedScreenError:
'=======================================================================
=============
' Two of the three "Screen" method statements will raise an error
condition because
' there will only be control elements for whatever type of screen is
currently open,
' be it a report, form or other control.
'=======================================================================
=============
If Err.Number = 2474 Then 'In fact a screen error? (Steele
thought it was 2476?)
Resume Next 'Yes, we'll ignore it
Else
MsgBox Err.Number & ": " & Err.Description, vbOKOnly +
vbCritical Resume End_HTMLctxHelp
End If

End Function


With a "Report" in currently displayed in preview,
error 2474 is raised for the Screen.ActiveControl,
but the error routine DOES NOT get control.

Note in passing: in this line ...
FrmCtxID = Screen.ActiveControl.HelpContextId

.... I think you meant that to be "Screen.ActiveForm".

Anyway, to your question. In the VB Editor, in the Tools -> Options...
dialog, on the General tab, do you have "Break on All Errors" selected
as the error-handling option?
 

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