MS Access

Assigning a Macro to a Keystroke Combination

The AutoKeys

Sometimes, instead of assigning a macro to a command button, you may want to assign it to a specific keystroke combination, such as Ctrl + D. Assigning a keystroke combination to a macro makes it fast and easy to accessyou can execute the macro at any time by pressing its assigned keystroke combination.

Assigning a keystroke combination to macro can be a somewhat complicated process. There are two things you need to know about assigning a macro to a keystroke combination:

  • You must create a special macro group, named , which contains all your keystroke-combination macros.

  • You type the keystroke combination to which you want to assign the macro in the Macro Name column of the AutoKeys macro window. Enter the keystroke combinations using the examples in table. For example, to assign a macro to the keystroke combination Ctrl + D, you would name the macro ^D.

In this lesson you will learn how to create an AutoKeys macro to assign a macro to a keystroke combination.

  1. In the Database window, click the Macros icon in the Objects bar and then click the New button.

    The Macro window appears. You need to make sure the Macro Name column is displayed in order to tell Access which keystroke combination you want to assign to the macro.

  2. Click the Macro Names button on the toolbar, if necessary.

    Now you need to type the keystroke combination to which you want to assign the macro. Table shows the key combinations you can use to make key assignments in an AutoKeys macro group. We want to assign a macro to the keystroke combination Ctrl + L. Here's what you need to enter:

  3. Type ^L in the first blank Macro Name cell, as shown in figure.

    The name ^L refers to Ctrl + L. The ^ (caret) signifies the Ctrl key and the "L" signifies the "L" key.

    If you assign a macro to a keystroke combination that Microsoft Access is already using (for example, Ctrl + X is the keystroke combination for the Cut command), the macro you assign to this keystroke combination will override the Microsoft Access keystroke combination assignment.

    Now we need to specify what we want the macro to do.

  4. Click the first blank Action cell, click the list arrow, and select RunApp from the list.

    The RunApp action starts another program, such as Microsoft Excel or Word. We want the RunApp action to start the Calculator program. You need to specify the name and location of the program you want to run in the Action Arguments area.

  5. Click the Command Line text box and type calc.exe.

    Now let's save the macro, making sure that we name it AutoKeys.

  6. Click the Save button on the toolbar, type AutoKeys, and click OK.

    We're ready to test our AutoKeys macro.

  7. Press Ctrl + L.

    Microsoft Access executes the macro assigned to the Ctrl + L keystroke combination and starts the Calculator application.

  8. Close the AutoKeys macro and the Lesson 10 database.

Give yourself a pat on the back if you've gotten through this tutorial. You've just learned how to automate your Microsoft Access databases to work more like a full-featured application instead of a dull, static database.

The SendKey Syntax
Heading Heading

Ctrl + Any Key

^ (For example, enter ^E for Ctrl + E.)

Shift + Any Key

+ (For example, enter +E for Shift + E.)

Alt

% (For example, enter %E for Alt + E.)

Enter

{ENTER}

Esc

{ESC}

Tab

{TAB}

Insert, Delete

{INSERT} or {INS}, {DELETE} or {DEL}

Page Down, Page Up

{PGDN}, {PGUP}

Home, End

{HOME}, {END}

Arrow Keys

{UP}, {DOWN}, {LEFT}, {RIGHT}

Caps Lock

{CAPSLOCK}

Function Keys

{F1}, {F2}, {F3}, etc...


TO ASSIGN A MACRO TO A KEYSTROKE COMBINATION:

  1. CREATE A MACRO GROUP NAMED AUTOKEYS. THIS WILL STORE ALL THE MACROS THAT ARE ASSIGNED TO A KEYSTROKE COMBINATION.

  2. CLICK THE MACRO NAMES BUTTON ON THE TOOLBAR.

  3. TYPE THE KEYSTROKE COMBINATION IN SENDKEY SYNTAX IN THE MACRO NAME COLUMN NEXT TO THE ACTION WHERE THE MACRO STARTS. SEE TABLE.

by BrainBellupdated
Advertisement: