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



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q210166
Advanced: Requires expert coding, interoperability, and multiuser skills.

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

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.

  1. Start Microsoft Access
  2. Open the sample database Northwind.mdb or the sample project NorthwindCS.adp.
  3. In the Database window, under the Objects section, 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 Objects section, 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 Objects section, 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.

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

For more information about HelpContextID, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type helpcontextid property in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Modification Type:MajorLast Reviewed:12/29/2005
Keywords:kbProgramming kbfunctions kbsampledatabase kbhowto kbinfo kbusage KB210166 kbAudDeveloper