Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


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

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

↑ Back to the top


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.

↑ Back to the top


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

  1. Start Microsoft Access
  2. Open the sample database Northwind.mdb or the sample project NorthwindCS.adp.
  3. In the Database window, under the Objectssection, click Modules.
  4. Click New.
  5. 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.
  6. 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
  7. Save the module as HelpModule.
  8. Close the Visual Basic Editor.
  9. In the Database window, under the Objectssection, click Macros.
  10. Click New.
  11. Create the following new macro to redirect the F1 key:

    Macro Name Action Action Arguments
    --------------------------------------------------------
    {F1} RunCode Function Name: Help32()
  12. Save the macro as AutoKeys, and then close the macro.
  13. In the Database window, under the Objectssection, click Forms.
  14. In the right pane, double-click Suppliers.
  15. Press the F1 key.
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

  1. Start Microsoft Access
  2. Open the sample database Northwind2007.accdb.
  3. On the Create tab, click the down arrow below Macro, and then click Module.
  4. 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.
  5. 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
  6. Save the module as HelpModule.
  7. Close the Visual Basic Editor.
  8. On the Create tab, click Macro.
  9. Create the following new macro to redirect the F1 key:

    Macro Name Action Action Arguments
    --------------------------------------------------------
    {F1} RunCode Function Name: Help32()
  10. Save the macro as AutoKeys, and then close the macro.
  11. Click Suppliers in the left pane.
  12. In the left pane, double-click Supplier List.
  13. Press the F1 key.
Observe that the Microsoft Access displays the help message, corresponding to the helpContextID of the control or the form, in a pop-up box.

↑ Back to the top


References

For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:

828419 How to create an HTML Help system by using either the HTMLHelp API or the HTML Help in Access

242433 How to create context sensitive HTML Help files

↑ Back to the top


Keywords: offcon, ocsentirenet, kbusage, kbinfo, kbhowto, acccon, kbswept, kbsampledatabase, kb, kbsweptsoltax, kbfunctions, kbprogramming, kboffice12yes, kbfreshness2007, kboffice2003yes

↑ Back to the top

Article Info
Article ID : 210166
Revision : 3
Created on : 4/17/2018
Published on : 4/19/2018
Exists online : False
Views : 251