Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how does one disable a key (escape) ????? 1

Status
Not open for further replies.

General

Programmer
Aug 13, 2000
3
AU
Try to disable the escape key in an access app. If this can't be done how do i go about handling the event so that it do something other than clearing data just entered???
 
Have you tryed to change the action of the key in the preferences menu? Also, use the [tt]KeyPressed[/tt] event to detect the [tt]KeyCode[/tt] property of the key. Then take action. The code of Esc is $27 or use the constant vbKeyEsc.
 
I use the form key_down event. Check this out.
When the user presses the escape key nothing happens!

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

On Error GoTo HandleErrors

Select Case KeyCode
Case vbKeyEscape
KeyCode = 0
End Select

Exit_Form_KeyDown:
Exit Sub

HandleErrors:
KeyCode = 0 'prevents access from raising an error
Resume Exit_Form_KeyDown

End Sub
[sig]<p>John A. Gilman<br><a href=mailto:gms@uslink.net>gms@uslink.net</a><br>[/sig]
 
JohnneyRingo:
I think this is because your Form doesn't have the Focus, one of your controls ON the form does. How to avoid this? I'm not certain, other than (yikes) creating a function, and setting a call to that function for EACH control's KeyDown (or KeyPress, whatevah) event.

Other than this, I believe there is a Windows API call that you can make to disable, or catch the Esc press. I'm not certain, I haven't tried that before.
 
I'm not sure anyone is still following this, but the solution from JohnnyRingo is a good one--thanks for the idea. To have a form with enable controls react to key press events requires using the KeyPreview property (following copied form Access help):
[tt]
A form will also receive all keyboard events, even those that occur for controls, if you set the KeyPreview property of the form to Yes. With this property setting, all keyboard events occur first for the form, and then for the control that has the focus. You can respond to specific keys pressed in the form, regardless of which control has the focus. For example, you may want the key combination CTRL+X to always perform the same action on a form.[/tt]
 
My my my, Thank you!
*MoGryph doubts his skillz*

I hadn't seen that blurb in Access Help (not that Access help is that user friendly!) JohnnyRingo- in that case THANK YOU! You saved me much time in my CTRL-C/CTRL-V exercises. 8O) *'s for you.

Quehay- Thank you for your ammendum to Johnny's post, pointing out the beauty of his idea. *'s for you as well, especially for your ability to scour Access Help.

-MoGryph
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top