The KeyPress event will allow you to do that. You must also turn on the Key Preview property to YES and use the following...
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
KeyAscii = 0
Beep
MsgBox "You can not use the Esc key.", vbInformation, "Invalid Key Stroke"
Else
'do nothing since they did not use the Esc key
End If
End Sub
I did not put my question right. I want to run a query on a form. That
query works with big amount of data and it needs a few minutes to end.
I need to block "escape" key while query runs - becouse "escape" is stoping my query in the middle. If I block this key on a form (keypress) it doesn't help.
You could use an AutoKey macro to override what the Esc keys normally does. Search the forum and/or Access help files on how to create and use the AutoKey macro.