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

ID: Q120827


The information in this article applies to:
  • Microsoft Access 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 : kbusage FmsEvnt
Version : 2.0
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: April 7, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.