Search code examples
vbams-accessms-access-2007chmhtml-help-workshop

Microsoft Access 2007 Database Application HTML Help opens multiple instances of chm file


We have created help file (.chm) using HTML Help Workshop,

In Access 2007 database Form property, we have set "Help File" = HelpApp.chm and "Help Context ID" propertiey = 1001, so when we press F1 it opens the help file with this context ID.

The problem is when we press F1 multiple times(once each for different form or help topic) it opens multiple instances of the help file. Also I observed if I press F1 on same form multiple times, it opens multiple instances as well.

We don't want to create multiple instances of help file.

How we can prevent openning the multiple instances of help file?

Database Application being developed in Microsoft Access 2007 , .accdb file format.

Help file being created HTML Help workshop 4.74.8702.0

I searched internet but there was no article that has multiple help file instances opening issue in Microsoft Access application. But there is one article that discusses for C# application,

How do I limit my Windows application to spawning a single instance of a process?

I don't know if the above solutions, to check whether the Process has exited ? OR ProcessStartInfo ? but I need this in VBA.


Solution

  • This problem is difficult and depends on how the help is invoked. You must give some more information and the calling VBA code. I have seen your issue with multiple instances of the help window only once after moving the Access window to a new position followed by pressing the F1 button. But never seen again yet.

    One thing I remember is a problem with hh.dat. The hh.dat file stores user-specific information on all the HTMLHelp files (*.CHM) on your system (position, favourite topics, search history, etc.), and can cause a error if it has somehow been corrupted. Delete or rename the file hh.dat to reset all (!) CHM windows on your system to their default settings. You should find hh.dat in this directory:

    \Documents and Settings\%username%\Application Data\Microsoft\HTML Help or

    C:\Users\%username%\AppData\Roaming\Microsoft\HTML Help

    Windows will create a new version of hh.dat when you next open any .chm file.

    Try to set F1 to AutoKeys (see snapshot).

    enter image description here

    Add a modul for invoking help by HTMLHelp API (see code sample):

    Option Compare Database
    Option Explicit
    
    '******************************************************************************
    '----- Modul - definition for HTMLHelp - (c) Ulrich Kulle, www.help-info.de
    '----- 2014-08-26 Version 0.1.9000
    '******************************************************************************
    
    Declare Function IsWindow Lib "user32.dll" (ByVal hWnd As Long) As Long
    
    Private Declare Function SendMessage Lib "user32" _
     Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
     ByVal wParam As Long, lParam As Any) As Long
    
    Private Declare Function HtmlHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" _
                    (ByVal hwndCaller As Long, ByVal pszFile As String, _
                    ByVal uCommand As Long, ByVal dwData As Long) As Long
    
    Declare Function HTMLHelpTopic Lib "hhctrl.ocx" Alias "HtmlHelpA" _
             (ByVal hwndCaller As Long, ByVal pszFile As String, _
             ByVal uCommand As Long, ByVal dwData As String) As Long
    
    Private Declare Function HtmlHelpSearch Lib "hhctrl.ocx" Alias "HtmlHelpA" _
            (ByVal hwndCaller As Long, ByVal pszFile As String, _
            ByVal uCommand As Long, dwData As HH_FTS_QUERY) As Long
    
    '--- to keep the handle of the HH windows when calling help by API --------
    Public HHwinHwnd As Long
    
    '--- some constants used by the API ---------------------------------------
    Public Const HH_DISPLAY_TOPIC = &H0     ' select last opened tab, [display a specified topic]
    Public Const HH_DISPLAY_TOC = &H1       ' select contents tab, [display a specified topic]
    Public Const HH_DISPLAY_INDEX = &H2     ' select index tab and searches for a keyword
    Public Const HH_DISPLAY_SEARCH = &H3    ' select search tab and perform a search
    
    Public Const HH_HELP_CONTEXT = &HF      ' display mapped numeric value in dwData
    
    Public Const HH_CLOSE_ALL = &H12
    
    Public Type HH_FTS_QUERY                ' UDT for accessing the Search tab
      cbStruct          As Long             ' Sizeof structure in bytes.
      fUniCodeStrings   As Long             ' TRUE if all strings are unicode.
      pszSearchQuery    As String           ' String containing the search query.
      iProximity        As Long             ' Word proximity.
      fStemmedSearch    As Long             ' TRUE for StemmedSearch only.
      fTitleOnly        As Long             ' TRUE for Title search only.
      fExecute          As Long             ' TRUE to initiate the search.
      pszWindow         As String           ' Window to display in
    End Type
    
    Public Function HFile(ByVal i_HFile As Integer) As String
    '----- Set the string variable to include the application path of helpfile
      Select Case i_HFile
    
      '//--- default help file
      Case 1
        HFile = CurrentProject.Path & "\CHM-example.chm"
      Case 2
    '----- Place other Help file paths in successive case statements
        HFile = CurrentProject.Path & "\CHM-example.chm"
      End Select
    End Function
    
    Public Sub OpenHelp(strHelpFile As String, lngID As Long)
        Dim hWnd As Long
        Dim strHelpFile As String
        strHelpFile = CurrentProject.Path & "\CHM-example.chm"
        hWnd = HtmlHelp(Application.hWndAccessApp, strHelpFile, HH_DISPLAY_TOC, lngID)
    End Sub
    
    Public Function CallHelp()
    '//--- TEST invoking help with different methods ----------------------------------
        'OpenHelp strHelpFile, 20010
        'ShowContents 1
        'ShowIndex 1
        'ShowSearch 1
        If Screen.ActiveForm.Name = "Coordinates-Form-1" Then
            MsgBox Screen.ActiveForm.Name
            ShowTopicID 1, 10010
        ElseIf Screen.ActiveForm.Name = "Coordinates-Form-2" Then
            MsgBox Screen.ActiveForm.Name
            ShowTopicID 1, 20010
        Else
            ShowContents 1
        End If
    End Function
    
    Public Sub ShowContents(ByVal intHelpFile As Integer)
        HHwinHwnd = HtmlHelp(Application.hWndAccessApp, HFile(intHelpFile), HH_DISPLAY_TOC, 0)
    End Sub
    
    Public Sub ShowIndex(ByVal intHelpFile As Integer)
        HHwinHwnd = HtmlHelp(Application.hWndAccessApp, HFile(intHelpFile), HH_DISPLAY_INDEX, 0)
    End Sub
    
    Public Sub ShowTopic(ByVal intHelpFile As Integer, strTopic As String)
        HHwinHwnd = HTMLHelpTopic(Application.hWndAccessApp, HFile(intHelpFile), HH_DISPLAY_TOPIC, strTopic)
    End Sub
    
    Public Sub ShowTopicID(ByVal intHelpFile As Integer, IdTopic As Long)
        HHwinHwnd = HtmlHelp(Application.hWndAccessApp, HFile(intHelpFile), HH_HELP_CONTEXT, IdTopic)
    End Sub
    
    '------------------------------------------------------------------------------
    '----- display the search tab
    '----- bug: start searching with a string dosn't work
    '------------------------------------------------------------------------------
    Public Sub ShowSearch(ByVal intHelpFile As Integer)
    Dim searchIt As HH_FTS_QUERY
      With searchIt
        .cbStruct = Len(searchIt)
        .fUniCodeStrings = 1&
        .pszSearchQuery = "foobar"
        .iProximity = 0&
        .fStemmedSearch = 0&
        .fTitleOnly = 1&
        .fExecute = 1&
        .pszWindow = ""
      End With
      Call HtmlHelpSearch(0&, HFile(intHelpFile), HH_DISPLAY_SEARCH, searchIt)
    End Sub