Douglas,
Thanks for your suggestion. My code now reads:
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.
With the same "Report" displayed AND the
Screen.ActiveControl commented out, error 2475
is raised when the Screen.ActiveControl statement
is reached. I didn't have any trace turned on so I
don't know if the error handler fired or not.
Did I not follow your suggestion correctly?
Bill