Microsoft Office 2000/Visual Basic Programmer's Guide |
The Raise method of the Err object has optional helpfile and helpcontext arguments that set the HelpFile and HelpContext properties of the Err object to the specified Help file name and context ID when your custom error is triggered. If the error trap in your procedure then passes these values to the MsgBox function, you can add a Help button to call additional Help from your error message dialog box. The following code example shows how to do this:
Sub ShowErrorHelp()
Dim strAppPath As String
strAppPath = ActiveDocument.Path
On Error GoTo ShowErrorHelp_Err
Err.Raise Number:=vbObjectError + 1234, _
Source:="Sub ShowErrorHelp", _
Description:="This error has a reason.", _
HelpFile:=strAppPath & "\sample.chm", _
HelpContext:=2003
ShowErrorHelp_End:
Exit Sub
ShowErrorHelp_Err:
MsgBox Prompt:=Err.Description, _
Buttons:=vbMsgBoxHelpButton, _
HelpFile:=Err.HelpFile, _
Context:=Err.HelpContext
Resume ShowErrorHelp_End
End Sub
The ShowErrorHelp procedure is available in the modHTMLHelp module in the WordHelp.doc in the ODETools\V9\Samples\OPG\Samples\CH13 subfolder on the Office 2000 Developer CD-ROM.
The helpfile and helpcontext arguments of the Raise method support using a compiled HTML Help file in all Office applications, including Word and Access. There is no need to use the HtmlHelp API to display a Help topic in a .chm file when you are using the Raise method to return a Help file name and context ID in Word and Access.