Run a Macro with a Shortcut

R

rudolph

Hi :

I Assigned a macro to a shortcut F5, for that I used
Autokeys.

But, the problem is that this F5 is available in all the
forms so Everytime that I press F5 in any form , the code
associated to this macro is executed.

How can I execute the macro with the F5 key only in a
particular Form? Any ideas?


Thanks
 
T

tina

try this: create a public function, as

Public Function F5Shortcut()

If Screen.ActiveForm.Name = "Form1" Then
DoCmd.RunMacro "show message"
End If

End Function

change "Form1" to the name of your form that you want the
F5 shortcut to run from.
change "show message" to the name of your macro that you
want the F5 shortcut to execute.
then open your AutoKeys macro. instead of Action RunMacro,
use Action RunCode. Enter the Function Name at the bottom
as
F5Shortcut()
do not precede it with an = sign.

if you're comfortable with VBA, you could skip running a
macro entirely, instead using

Public Function F5Shortcut()

If Screen.ActiveForm.Name = "Form1" Then
'do here, whatever things
'the macro is currently doing
'for you.
End If

End Function

hth
 
R

Rudolph

Tina:

Thanks very much, now my code is working like a charm,
only on a particular form.

CHeers.

Rudolph.
 

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