ACC2000: How to Programmatically Display a Help File

Article translations Article translations
Article ID: 209843 - View products that this article applies to.
This article was previously published under Q209843
This article has been archived. It is offered "as is" and will no longer be updated.
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

Expand all | Collapse all

On This Page

Summary

This article shows you three techniques that you can use to programmatically display a Help file.

More information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Method 1

You can use the Shell command to display a Help file. To do so, follow these steps:
  1. Create a new form.
  2. Add a command button to the form.
  3. In the Click event of the command button, type one of the following two lines of code:
    Shell "Winhlp32.exe C:\Windows\Help\Access.hlp", vbNormalFocus
    					
    or
    Shell "HH.exe C:\Windows\Help\Access.chm", vbNormalFocus
    					
NOTE: You should verify the name and path to the Help file that you want to use.

Method 2

When you run the code in Method 1 for the first time, the form will most likely open on the Contents tab of the Help file. However, if you then switch to the Index tab, close the Help file, and run the code again, the Index tab will be displayed. Whichever tab was last active is displayed each time that you run the code.

If you have Microsoft Office 2000 Developer, you can avoid this behavior by using the Common Dialog control. To do so, follow these steps:
  1. On a new form, click ActiveX Control on the Insert menu.
  2. In the Insert ActiveX Control dialog box, select the Microsoft Common Dialogs Control, version 6.0, and click OK. Microsoft Access should give it the name ActiveXCtl0.
  3. Add a command button to the form.
  4. Type the following code for the Click event of the command button:
    With ActiveXCtl0    'Refers to the common dialog control.
        .HelpFile = "C:\Windows\System\Calc.hlp"
        .HelpCommand = 15
        .ShowHelp
    End With
    					
  5. View the form in Form view and click the button. The Contents tab appears.
  6. Switch to the Index tab, and then close the Help file.
  7. Click the button again. Note that the Contents tab re-appears. The Help file does not open with the Index tab active.
NOTE: If you change the value assigned to .HelpCommand from 15 to 11, you should get the same results as when using the Shell command to open the Help file.

Method 3

A more powerful way to display a Help file is to use Microsoft Windows API calls. These require some functions that you must first type into a module. To do so, open a new module, and type the following code. (Descriptions of how to use each of these API functions appear at the end of this article.)

NOTE: You may have some Microsoft Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive a duplicate procedure name error message, remove or comment out the declarations statement in your code.

Option Compare Database
Option Explicit

Public Const HELP_CONTEXT = &H1         'Display topic for Help context ID.
Public Const HELP_QUIT = &H2            'Terminate Help.
Public Const HELP_INDEX = &H3           'Display Help index.
Public Const HELP_CONTEXTPOPUP = &H8&   'Display Help context as a pop-up
                                        'window.
Public Const HELP_FINDER = &HB&         'If found, Display container file.
Public Const HELP_KEY = &H101           'Display topic for keyword.

'Declare the WinHelp function.
Declare Sub WinHelp Lib "user32" Alias "WinHelpA" (ByVal Hwnd As Long, _
    ByVal lpHelpFile As String, ByVal wCommand As Long, _
    ByVal dwData As Any)

Function OpenHelpContainer(ByVal strHelpFileName As String)
    'Opens the Help container.
    WinHelp Application.hWndAccessApp, ByVal strHelpFileName, _
        HELP_FINDER, ByVal vbNullString
End Function

Function OpenHelpIndex(ByVal strHelpFileName As String)
    'Opens the Help index.
    WinHelp Application.hWndAccessApp, ByVal strHelpFileName, HELP_KEY, _
        ByVal ""
End Function

Function OpenHelpIndexWithSearchKey(ByVal strHelpFileName As String, _
        ByVal strSearchKey As String)
    'Opens the Help index and searches for keyword SKey.
    WinHelp Application.hWndAccessApp, ByVal strHelpFileName, HELP_KEY, _
        ByVal strSearchKey
End Function

Function OpenHelpWithContextID(ByVal strHelpFileName As String, _
        lngContextID As Long)
    'Opens the Help file to ContextID.
    WinHelp Application.hWndAccessApp, ByVal strHelpFileName, _
        HELP_CONTEXT, ByVal lngContextID
End Function

Function OpenHelpWithContextIDPopup(ByVal strHelpFileName As String, _
        lngContextID As Long)
    'Opens the Help file to ContextID as a pop-up window.
    WinHelp Application.hWndAccessApp, ByVal strHelpFileName, _
        HELP_CONTEXTPOPUP, ByVal lngContextID
End Function

Function CloseHelpContainer(ByVal strHelpFileName As String)
    'Closes the specified Help file.
    WinHelp Application.hWndAccessApp, ByVal strHelpFileName, HELP_QUIT, _
        ByVal vbNullString
End Function
				
The above code provides some useful functions for displaying Help files. The list below describes the purpose of each.

NOTE: The following examples use the Help file "Calc.hlp", because it is usually in the System folder, and does not require a complete path.
  1. OpenHelpContainer()
    You can use the OpenHelpContainer function simply to open a Help file. To test this function, type the following in the Immediate window, and then press ENTER:
    ?OpenHelpContainer("Calc.hlp")
    						
    This opens the Help file for the Microsoft Windows Calculator.
  2. OpenHelpIndex()
    Opens the Help file with the Index tab activated. To test this function, type the following in the Immediate window, and then press ENTER:
    ?OpenHelpIndex("Calc.hlp")
    						
    This opens the Help file for the Microsoft Windows Calculator with the Index tab displayed.
  3. OpenHelpIndexWithSearchKey()
    Opens the specified Help index and searches for a keyword. To test this function, type the following in the Immediate window, and then press ENTER:
    ?OpenHelpIndexWithSearchKey("calc.hlp","simple calculations")
    						
    Note that the "Simple Calculations" topic ID is displayed.
  4. OpenHelpWithContextID()
    Opens the Help file to a specified ContextID. To test this function, type the following in the Immediate window, and then press ENTER:
    ?OpenHelpWithContextID("calc.hlp",90)
    						
    Note that it opens Help for the division button.
  5. OpenHelpWithContextIDPopup()
    Opens the Help file to a specified ContextID as a pop-up window. To test this function, type the following in the Immediate window, and then press ENTER:
    ?OpenHelpWithContextIDPopup("Calc.hlp",90)
    						
    Note that it opens Help for the division button in a pop-up window.
  6. CloseHelpContainer()
    Closes the Help file. To test this function, type the following in the Immediate window, and then press ENTER:
    ?CloseHelpContainer("Calc.hlp")
    						
    This should close the Microsoft Windows Calculator Help file if it is open.

References

For more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:
226118 OFF2000: Programming Resources for Visual Basic for Applications

Properties

Article ID: 209843 - Last Review: October 25, 2013 - Revision: 4.0
Applies to
  • Microsoft Access 2000 Standard Edition
Keywords: 
kbnosurvey kbarchive kbhowto kbprogramming KB209843

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com