ACC2: Setting KeyCode=0 for KeyDown Does Not Ignore All Keys

Last reviewed: May 28, 1997
Article ID: Q120827
The information in this article applies to:
  • Microsoft Access version 2.0
  • Microsoft Access Developer's Toolkit version 2.0

SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

Setting KeyCode to 0 in the event procedure for a form or form control's OnKeyDown property does not trap all keys and key combinations.

STATUS

This behavior is by design.

MORE INFORMATION

Setting KeyCode to 0 causes the following keys and key combinations to be trapped:

   TAB         F6         F7
   SHIFT+TAB   SHIFT+F6   F2

The following keys and key combinations are not trapped:

   F1               F4                SHIFT+DEL
   CTRL+SHIFT+TAB   CTRL+TAB          ALT+TAB
   CTRL+C           CTRL+F            CTRL+H
   CTRL+N           CTRL+O            CTRL+P
   CTRL+S           CTRL+V            CTRL+X
   CTRL+Z           CTRL+SHIFT+HOME   END
   CTRL+ENTER       BACKSPACE         CTRL+INSERT
   SHIFT+INSERT     ALT+BACKSPACE     F11
   F12

The following keys are not trapped in the Microsoft Access Developer's Toolkit (ADT):

   F11   F12   SHIFT+F12

NOTE: F11 is ignored by the ADT, so there's no need to trap it.

Only the F11, not F12 or SHIFT+F12, key can be trapped in the AutoKeys macro. To trap F11 with an AutoKeys Macro, follow these steps:

  1. Create a macro named AutoKeys

  2. Type "{F11}" on the name line

  3. Choose CancelEvent as the action

Steps To Reproduce Behavior

  1. Open the sample database NWIND.MDB.

  2. Select the Customers table in the Database window, then click the AutoForm button on the toolbar.

  3. View the new form in Design view. Set the Contact Name text box's OnKeyDown property to the following event procedure:

          Sub Contact_Name_KeyDown (KeyCode As Integer, Shift As Integer)
              KeyCode = 0
          End Sub
    
    

  4. View the form in Form view and press some of the keys and key combinations listed earlier in this article.

Note that if you press TAB, nothing happens, since this key does not get trapped. If you press CTRL+TAB, the next control is selected, since this key combination does not get trapped.

REFERENCES

Microsoft Access "Building Applications," version 2.0, Chapter 8, "Events," page 200

For more information about the KeyDown event, search for "KeyDown," and then "KeyDown, KeyUp Events" using the Microsoft Access Help menu.


Additional query words: keyup
Keywords : FmsEvnt kbusage
Version : 2.0
Platform : WINDOWS
Hardware : X86
Issue type : kbprb
Resolution Type : Info_Provided


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.