Dis-abling Enter

  • Thread starter Thread starter -z
  • Start date Start date
Z

-z

I use A2K

On a form (frmXYZ), I want on open for the <Enter> key to be disabled and
stay disabled throughout the form use. How do I code this action?

Thank you...
 
It can be done... You need to follow these steps:
1. Open the form in Design View, and click F4. This will open the Properties
Page. Click thw All tab, and find the Key Preview Property. Change it to
yes. In the on-line help there is the reason for it:

"KeyPreview Property
You can use the KeyPreview property to specify whether the form-level
keyboard event procedures are invoked before a control's keyboard event
procedures. Read/write Boolean.

expression.KeyPreview

expression Required. An expression that returns one of the objects in the
Applies To list.

Remarks
The KeyPreview property uses the following settings.

Setting Visual Basic Description
Yes True The form receives keyboard events first, then the active
control receives keyboard events.
No False (Default) Only the active control receives keyboard events.

You can set the KeyPreview property by using the form's property sheet, a
macro, or Visual Basic.
You can set the KeyPreview property in any view.

You can use the KeyPreview property to create a keyboard-handling procedure
for a form. For example, when an application uses function keys, setting the
KeyPreview property to True allows you to process keystrokes at the form
level rather than writing code for each control that might receive keystroke
events.

To handle keyboard events only at the form level and prevent controls from
receiving keyboard events, set the KeyAscii argument to 0 in the form's
KeyPress event procedure, and set the KeyCode argument to 0 in the form's
KeyDown and KeyUp event procedures.

If a form has no visible or enabled controls, it automatically receives all
keyboard events."
Now you will need to code the form's KeyDown Event:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
KeyCode = 0
End If
End Sub
 
Back
Top