Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Help Shortcut 1

Status
Not open for further replies.

dynamictiger

Technical User
Joined
Dec 14, 2001
Messages
206
Location
AU
I have created a help file and this works fine, as context sensitive help.

I thought it would be a good idea to add a shortcut to my help file on the custom toolbar. I have worked out this could be done through the New Menu item, I think. After that I'm lost, anyone got an idea?
 
The simplest way to call your help file is to use the Sendkeys statement. I'm assuming all your objects have their 'Helpfile' properties set to your help file name (forms & reports). If you have context sensitive help set up, pressing the F1 key will bring up your custom help. Using Sendkeys "{F1}" will mimick this behavior.

To make it work just create a macro that calls Sendkeys or create a public function in a standard module that calls sendkeys and enter the name of the macro (or function) as the 'On Action:' property for your menu item (Right-click the menu, click customize, then right-click the menu item and click 'Properties' to bring up the menu properties.

The property would look like this:

On Action: =OpenHelp()

The public function would look like this:

Public Function OpenHelp()
Sendkeys "{F1}"
End Function

If you need more control of your help system then you'll have to do a bit more work and utilize the windows API.

Here is a sample of what I use to open helpfiles from within my programs. First I declare the API function and constants in a module:

'********************
' API FUNCTIONS
'********************
Public 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

'********************
' WINHELP API CONSTANTS
'********************
Public Const HELP_COMMAND = &H102&
Public Const HELP_CONTENTS = &H3&
Public Const HELP_CONTENTS40 = &HB ' Required for 4.0 Help
Public Const HELP_CONTEXT = &H1 ' Display topic in ulTopic
Public Const HELP_CONTEXTPOPUP = &H8&
Public Const HELP_FORCEFILE = &H9&
Public Const HELP_HELPONHELP = &H4 ' Display help on using help
Public Const HELP_INDEX = &H3 ' Display index
Public Const HELP_KEY = &H101 ' Display topic for keyword in offabData
Public Const HELP_MULTIKEY = &H201&
Public Const HELP_PARTIALKEY = &H105&
Public Const HELP_QUIT = &H2 ' Terminate help
Public Const HELP_SETCONTENTS = &H5&
Public Const HELP_SETINDEX = &H5 ' Set current Index for multi index help
Public Const HELP_SETWINPOS = &H203&
Public Const HELPMSGSTRING = "commdlg_help"


The API wrapper looks like this:

Public Function ShowHelp(ByVal hWnd As Long, ByVal helpFile As String, ByVal userCmd As Long, dwData) As Long
On Error GoTo ErrHandler
Dim lngRet As Long
Dim lngData As Long
Dim strData As String
If userCmd = HELP_CONTEXTPOPUP Or userCmd = HELP_CONTEXT Then
lngData = CLng(dwData)
' The "&" tells windows to place 4 bytes on the stack.
lngRet = WinHelp(hWnd, helpFile, userCmd, ByVal lngData&)
ElseIf userCmd = HELP_PARTIALKEY Or userCmd = HELP_CONTENTS40 Then
strData = CStr(dwData)
' dwData is a string for help to search for.
lngRet = WinHelp(hWnd, helpFile, userCmd, ByVal strData$)
ElseIf userCmd = HELP_QUIT Then
' shut down help - pass null for dwData.
lngRet = WinHelp(hWnd, helpFile, userCmd, ByVal lngData&)
End If
ExitHere:
Exit Function
ErrHandler:
ShowHelp = -1
Resume ExitHere
End Function

Here is an example procedure that calls the first procedure to show help contents instead of context sensitive help (relies on the active form's help file property, but you can substitute any help file you like):

Public Function HelpContents()
On Error GoTo ErrHandler
Dim strHelpFile As String
Dim strPath As String
Dim hWnd As Long

strPath = GetDBPath() ' This is a custom function

' This could trigger an error if no form is active.
' Error handler will search the current DB path for
' the first help file it can find and attempt to use it.
strHelpFile = strPath & Screen.ActiveForm.helpFile

AppHwnd:

hWnd = Application.hWndAccessApp

Call ShowHelp(hWnd, strHelpFile, HELP_CONTENTS40, 0)

ExitHere:
Exit Function
ErrHandler:
' Error 2475 will trigger if no form is active,
' which leaves the strHelpFile variable empty.
If Not Len(strHelpFile) > 0 Then
strHelpFile = strPath & Dir(strPath & "*.hlp")
If Len(strHelpFile) > 0 Then
Resume AppHwnd
End If
End If
Resume ExitHere
End Function

With this setup you can tailor the help system the way you want to.

VBSlammer
 
I appreciate your assistance with this, it is the second example that suits my ambition. I already have context sensitive help enabled and an appropriate short cut for this.

Thanks once again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top