Microsoft KB Archive/120827

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

Article ID: 120827

Article Last Modified on 7/5/2002

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access Developer's Toolkit 2.0

-



This article was previously published under Q120827



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



SYMPTOMS
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
 Open the sample database NWIND.MDB. Select the Customers table in the Database window, then click the AutoForm button on the toolbar.  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  View the form in Form view and press some of the keys and key combinations listed earlier in this article.</li></ol>

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.

<div class="references_section">