Share via


Displaying Help by Using the InputBox and MsgBox Functions

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Both the InputBox and MsgBox functions provide optional helpfile and context arguments that can be used to display a Help topic when a user clicks the Help button or presses F1. To display a custom Help topic, you must specify both optional arguments. The helpfile argument is a string value that specifies the Help file that contains the topic you want to display. This argument can accept either a .chm or .hlp file. The context argument specifies the mapped context ID of the topic to display.

If you specify the helpfile and context arguments when you are using the InputBox function, a Help button will automatically be added to the dialog box created by the InputBox function. If you specify the helpfile and context arguments when you are using the MsgBox function, you must also specify the vbMsgBoxHelpButton built-in constant in the buttons argument in order to add a Help button to the dialog box created by the MsgBox function.

The following code fragment shows how to display a Help topic when you are using the InputBox function:

InputBox Prompt:="Enter data", _
         HelpFile:=strAppPath & "\sample.chm", _
         Context:="2001"

The following line of code shows how to display a Help topic when you are using the MsgBox function:

MsgBox Prompt:="You must enter a valid date.", _
       Buttons:=vbMsgBoxHelpButton, _
       HelpFile:=strAppPath & "\sample.chm", _
       Context:="2002"

The InputBox and MsgBox functions allow you to display a Help topic contained in 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 these functions in Word and Access.

See Also

Displaying Help from VBA Code | Displaying Help by Using the Help Method | Displaying Help by Using the HtmlHelp API | Displaying Help for Custom Error Messages | Displaying Help for Properties and Methods in Class Modules