Emulating F1 Help from Toolbar

D

Dan Bair

Hi;

I've asked this question before and got a good answer
from "Dave", but I guess I'm too dense to figure it out.

I'm developing in Office XP. I have a help file called
Project.hlp My "help" is working fine; when I
press "F1", the right help topic comes up for the right
form! Cool!

PROBLEM: Now what I want to do is "emulate"
pressing "F1" from the toolbar. In other words, I want
to be able to have a toolbar menu item called "Help".
When the user clicks on "Help", I want it to execute a
module that figures out what VBA form has focus and bring
up the help topic that matches that form's
helpcontextid. The module would have to look for the
help file in the same path/directory that my VBA project
is in.

Like I said, "Dave" gave me some code for the module and
I tried to use it, but can't even get it to compile.
Code is marked in red and I can't figure out what's wrong
with it. I'm pretty new at VBA coding.

DAVE'S RESPONSE:

Place the following function in a module, and then call
it
from the button click event, passing the the full path of
the helpfile and the contextID

Function OpenHelpWithContextID(ByVal strHelpFileName As _
String, lngContextID As Long)

' Opens the Help file to ContextID.

WinHelp Application.hWndAccessApp, ByVal strHelpFileName,
_
HELP_CONTEXT, ByVal lngContextID

End Function

You need to place this constant

Public Const HELP_CONTEXT = &H1

In the general section of the module and this also

Declare Sub WinHelp Lib "user32" Alias _
"WinHelpA" (ByVal hWnd As Long, ByVal lpHelpFile As
String, _
ByVal wCommand As Long, ByVal dwData As Any)
--------------------------------------------------------
I can't get the "Declare" code to compile. Can somebody
give me another clue?

Thanks,
Dan
 
D

Dev Ashish

Declare Sub WinHelp Lib "user32" Alias _
"WinHelpA" (ByVal hWnd As Long, ByVal lpHelpFile As
String, _
ByVal wCommand As Long, ByVal dwData As Any)

What's the error you are getting? Are you sure that you're not dealing with
line wraps? Either put the WinHelp declaration all on one line or try this
instead.

Declare Sub WinHelp Lib "user32" _
Alias "WinHelpA" ( _
ByVal hWnd As Long, _
ByVal lpHelpFile As String, _
ByVal wCommand As Long, _
ByVal dwData As Any)

-- Dev
 
D

Dan Bair

-----Original Message-----
[email protected]:
What's the error you are getting? Are you sure that you're not dealing with
line wraps? Either put the WinHelp declaration all on one line or try this
instead.

Declare Sub WinHelp Lib "user32" _
Alias "WinHelpA" ( _
ByVal hWnd As Long, _
ByVal lpHelpFile As String, _
ByVal wCommand As Long, _
ByVal dwData As Any)

-- Dev
.
Thanks Dev;
It was the line wraps. I can get the code in the module
now, but when I try to autoexec it, I get the message;

"The object doesn't contain the Automation
object '<<strHelpFileName>>."

Being really new at this, am I supposed to load
strHelpFileName with the path/directory/helpfilename?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top