Click to See Complete Forum and Search --> : KeyPreview property of form
Shella
November 3rd, 1999, 11:00 AM
Hi
I've set the KeyPreview property of form1 to true so that I can cancel any ADD OPERATIONS by pressing ESCAPE. Okay, this function works well for me, but I found that if the Focus is on a DBCOMBO BOX, I can't cancel ADD OPERATION by pressing ESCAPE, the event, Private Sub Form_KeyPress(KeyAscii As Integer)
wouldn't be triggered, why ? If the Focus is on a Maskedbox, this event would be triggered when any key pressed. Thanx for telling in advance.
Crazy D @ Work
November 4th, 1999, 02:57 AM
Check the KeyDown event (KeyCode = vbKeyEscape)
That's usually the best place to catch keys like escape
Crazy D @ Work :-)
Sky1000
November 4th, 1999, 01:37 PM
The keydown event happens before the keypress event which is followed by the keyup event. If the keypreview property for your form is set to true, you "should" be able to modify or cancel key events that are sent to a control. If you are running some sort of cancel routine from the escape key at the form level, you probably wouldn't want to send the keystroke event to the control, so in your form-level keypress routine if keyAscii = vbKeyEscape, then KeyAscii = 0, and cancel whatever process you want to cancel, or you can set KeyCode = 0 if you are intercepting strokes from the keydown event. But this is what the VB documentation states: "Some controls intercept keyboard events so that the form can't receive them. Examples include the ENTER key when focus is on a CommandButton control and arrow keys when focus is on a ListBox control."
So if that is the case with your control, and you want have your stated functionality, you might have to use the API to intercept keystrokes.
Sky1000
Shella
November 5th, 1999, 11:48 AM
Hi
I found that the form cannot receive keyboard events only for the keypress of Escape Key, F1-F12 and other Non-Printing Keys WHEN A FOCUS IS ON A [b]DBCombo Box.[b] Why ?
Shella
November 5th, 1999, 11:52 AM
Hi
Nope, the form cannot catch those Non-printing Key Keypress WHEN A FOCUS IS ON A DBCOMBO BOX, (for other controls like Maskedbox, text box have no problems, only DBCOMBO BOX), means that either FORM_Keydown or Form_Keypress events won't be triggered.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.