Microsoft KB Archive/210166

= How to create pop-up context-sensitive Help by using Windows API WinHelp =

Article ID: 210166

Article Last Modified on 4/6/2007

-

APPLIES TO


 * Microsoft Office Access 2007
 * Microsoft Office Access 2003
 * Microsoft Access 2002 Standard Edition
 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210166



Advanced: Requires expert coding, interoperability, and multiuser skills.



For a Microsoft Access 97 version of this article, see 141621.



SUMMARY
One alternative to displaying your application's online Help system in a separate window is to display it in a small, shaded pop-up window in your application. To do this, you can use the Windows API WinHelp function with its HELP_CONTEXTPOPUP argument. This article shows you how to implement such a Help system.

This article assumes that you are familiar with using the Microsoft Windows Help Workshop to create Windows Help files.



MORE INFORMATION
The Windows API WinHelp function supports a large number of options. The HELP_CONTEXTPOPUP option opens a shaded pop-up window in which you can display Help. This window is similar to the window that opens when you click a glossary entry (green, underlined text) in the Microsoft Access Help system.

To implement this feature, follow these steps:
 * Create a working Help system by setting the HelpContextID and HelpFile properties for your forms to a valid Windows Help file.
 * Redirect the F1 key to call a user-defined function that opens the Help file using the HELP_CONTEXTPOPUP option.

Note that jumping or branching to other Help topics from the pop-up Help window is not supported by the methods discussed in this article.

The following steps describe how to create the user-defined function to open the pop-up Help window and how to redirect the F1 key:

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

Access 2000, Access 2002, and Access 2003
 Start Microsoft Access Open the sample database Northwind.mdb or the sample project NorthwindCS.adp. In the Database window, under the Objects section, click Modules. Click New.  In the Visual Basic Editor, type or paste the following code in the Declarations section: Declare Function WinHelp Lib "user32" Alias "WinHelpA" _ (ByVal hwnd As Long, _                 ByVal lpHelpFile As String, _                  ByVal wCommand As Long, _                  ByVal dwData As Long) As Long Public Const HELP_CONTEXTPOPUP = &H8& 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.   Append the following code in the Visual Basic Editor: Function Help32 As Boolean On Local Error GoTo Help32_Err Dim Cid As Long, Result As Long On Error Resume Next ' Get the HelpContextID of the active control. ' The error is 2474 if no control is active. Cid = Screen.ActiveControl.HelpContextId

If Cid = 0 Then ' There is no control context ID, so check the form and get ' the HelpContextID of the active form. ' The error is 2475 if no form is active. Cid = Screen.ActiveForm.HelpContextId End If

' If there is a context ID, open the Help file with context. ' Specify your custom Help file for the second argument. ' This example used the default help file NWIND9.HLP located ' in the Office Samples folder. ' If the NWIND9.HLP is not available, then replace the ' specified path with a valid Winhelp file, and modify the code and ' the HelpContextID of the Forms and Controls accordingly.

If Cid > 0 And Cid < 32767 Then Result = WinHelp(Application.hWndAccessApp, _     "C:\Program Files\Microsoft Office\Office\Samples\nwind9.hlp", _      HELP_CONTEXTPOPUP, Cid) Help32 = True End If

Help32_End: Exit Function

Help32_Err: MsgBox Err.Description Resume Help32_End End Function </li> Save the module as HelpModule.</li> Close the Visual Basic Editor.</li> In the Database window, under the Objects section, click Macros.</li> Click New.</li>  Create the following new macro to redirect the F1 key:

<pre class="fixed_text">  Macro Name     Action       Action Arguments {F1}       RunCode      Function Name: Help32 </li> Save the macro as AutoKeys, and then close the macro.</li> In the Database window, under the Objects section, click Forms.</li> In the right pane, double-click Suppliers.</li> Press the F1 key.</li></ol>

Observe that the Microsoft Access displays the help message, corresponding to the helpContextID of the control or the form, in a pop-up box.

Access 2007
<ol> Start Microsoft Access</li> Open the sample database Northwind2007.accdb.</li> On the Create tab, click the down arrow below Macro, and then click Module.</li>  In the Visual Basic Editor, paste the following code example in the Declarations section. Declare Function WinHelp Lib "user32" Alias "WinHelpA" _ (ByVal hwnd As Long, _                 ByVal lpHelpFile As String, _                  ByVal wCommand As Long, _                  ByVal dwData As Long) As Long Public Const HELP_CONTEXTPOPUP = &H8& 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. </li>  Append the following code example in the Visual Basic Editor. Function Help32 As Boolean On Local Error GoTo Help32_Err Dim Cid As Long, Result As Long On Error Resume Next ' Get the HelpContextID of the active control. ' The error is 2474 if no control is active. Cid = Screen.ActiveControl.HelpContextId

If Cid = 0 Then ' There is no control context ID, so check the form and get ' the HelpContextID of the active form. ' The error is 2475 if no form is active. Cid = Screen.ActiveForm.HelpContextId End If

' If there is a context ID, open the Help file with context. ' Specify your custom Help file for the second argument. ' This example used the default help file NWIND9.HLP located ' in the Office Samples folder. ' If the NWIND9.HLP is not available, then replace the ' specified path with a valid Winhelp file, and modify the code and ' the HelpContextID of the Forms and Controls accordingly.

If Cid > 0 And Cid < 32767 Then Result = WinHelp(Application.hWndAccessApp, _     "C:\Program Files\Microsoft Office\Office\Samples\nwind9.hlp", _      HELP_CONTEXTPOPUP, Cid) Help32 = True End If

Help32_End: Exit Function

Help32_Err: MsgBox Err.Description Resume Help32_End End Function </li> Save the module as HelpModule.</li> <li>Close the Visual Basic Editor.</li> <li>On the Create tab, click Macro.</li> <li> Create the following new macro to redirect the F1 key:

<pre class="fixed_text">  Macro Name     Action       Action Arguments {F1}       RunCode      Function Name: Help32 </li> <li>Save the macro as AutoKeys, and then close the macro.</li> <li>Click Suppliers in the left pane.</li> <li>In the left pane, double-click Supplier List.</li> <li>Press the F1 key.</li></ol>

Observe that the Microsoft Access displays the help message, corresponding to the helpContextID of the control or the form, in a pop-up box.

Additional query words: ACC2000 Access 2000 ACC2002 ACC2003 ACC2007

<div class="references_section">