How do I assign keyboard commands to a function I created?

  • Thread starter Thread starter Bill R via AccessMonster.com
  • Start date Start date
B

Bill R via AccessMonster.com

I need to be able to get rid of the hourglass, and reset echo and setwarnings
back to true. The function is easy to create, but how do I assign keystrokes
to it to activate it?

Bill
 
I need to be able to get rid of the hourglass, and reset echo and setwarnings
back to true. The function is easy to create, but how do I assign keystrokes
to it to activate it?

Bill

You can put a command button (or, if you prefer, a Label) on the Form;
put the code in its Click event, and use a Caption property with a
"hotkey". To define the hotkey precede one character in the caption
with an ampersand; this character will display underlined, and typing
Alt-<character> will fire the click event.

That is, you could have a command button with a caption property of
&Reset; it will be displayed a just the word Reset with the R
underlined. Either clicking the button or typing Alt-R will run the
code.

John W. Vinson[MVP]
 
That will work if I can see the button, but with echo off, I can't tell if
the button is on the form which is no longer visible or not, so I don't
believe the keystrokes would work then. Is there anyway to assign keystrokes
directly to the function in the VBE?
 
Try using an autokeys macro to run your code, or just build the equivalent in
the macro itself.

This worked in Access 97; however, I've not tested it recently in later versions.

Use an autokeys macro.

From Access97 help file:

You can assign an action or set of actions to a specific key or key combination
by creating an AutoKeys macro group. When you press the key or key combination,
Microsoft Access carries out the action.

1 In the Database window, click the Macros tab.
2 Click New.
3 Click Macro Names on the toolbar.
4 In the Macro Name column, type the key or key combination to which you want to
assign the action or set of actions.
5 Add the action or set of actions you want the key or key combination to carry
out. For example, you could add a RunMacro action that runs the Print Current
Record macro when CTRL+P is pressed. (^p in the macro column)
6 Repeat steps 4 and 5 for any other key assignments you want to make.
7 Save the macro group with the name AutoKeys.

The new key assignments are in effect as soon as you save the macro group and
each time you open the database.

Note If you assign a set of actions to a key combination that is already being
used by Microsoft Access (for example, CTRL+C is the key combination for Copy),
the actions you assign this key combination replace the Microsoft Access key assignment.

AutoKeys key combinations

The following table shows the key combinations you can use to make key
assignments in an AutoKeys macro group. These key combinations are a subset of
the syntax used in the SendKeys statement in Visual Basic. For more information
on the syntax of the SendKeys statement, click .


^A or ^4 CTRL+Any letter or number key
{F1} Any function key
^{F1} CTRL+Any function key
+{F1} SHIFT+Any function key
{INSERT} INS
^{INSERT} CTRL+INS
+{INSERT} SHIFT+INS
{DELETE} or {DEL} DEL
^{DELETE} or ^{DEL} CTRL+DEL
+{DELETE} or +{DEL} SHIFT+DEL
 
John,

That did it. Thanks a million.

Bill

John said:
Try using an autokeys macro to run your code, or just build the equivalent in
the macro itself.

This worked in Access 97; however, I've not tested it recently in later versions.

Use an autokeys macro.

From Access97 help file:

You can assign an action or set of actions to a specific key or key combination
by creating an AutoKeys macro group. When you press the key or key combination,
Microsoft Access carries out the action.

1 In the Database window, click the Macros tab.
2 Click New.
3 Click Macro Names on the toolbar.
4 In the Macro Name column, type the key or key combination to which you want to
assign the action or set of actions.
5 Add the action or set of actions you want the key or key combination to carry
out. For example, you could add a RunMacro action that runs the Print Current
Record macro when CTRL+P is pressed. (^p in the macro column)
6 Repeat steps 4 and 5 for any other key assignments you want to make.
7 Save the macro group with the name AutoKeys.

The new key assignments are in effect as soon as you save the macro group and
each time you open the database.

Note If you assign a set of actions to a key combination that is already being
used by Microsoft Access (for example, CTRL+C is the key combination for Copy),
the actions you assign this key combination replace the Microsoft Access key assignment.

AutoKeys key combinations

The following table shows the key combinations you can use to make key
assignments in an AutoKeys macro group. These key combinations are a subset of
the syntax used in the SendKeys statement in Visual Basic. For more information
on the syntax of the SendKeys statement, click .

^A or ^4 CTRL+Any letter or number key
{F1} Any function key
^{F1} CTRL+Any function key
+{F1} SHIFT+Any function key
{INSERT} INS
^{INSERT} CTRL+INS
+{INSERT} SHIFT+INS
{DELETE} or {DEL} DEL
^{DELETE} or ^{DEL} CTRL+DEL
+{DELETE} or +{DEL} SHIFT+DEL
 
Back
Top