How to disable special keys in a form?

  • Thread starter Thread starter M.Tavassoli
  • Start date Start date
M

M.Tavassoli

Hi;
I want to disable effect of some keys such as F1,F2,Page Down,Page Up and so
on,in a form and use my own SubRouthines for them.How to do that?
Thank you for your help.
 
Set the form's KeyPreview property to Yes.
Use the form's KeyDown event to trap the keystrokes.
Call your own routines, and destroy the keystoke by setting KeyCode to zero.

Use constants like vbKeyF1 to match the KeyCode.
 
Thank you.

Allen Browne said:
Set the form's KeyPreview property to Yes.
Use the form's KeyDown event to trap the keystrokes.
Call your own routines, and destroy the keystoke by setting KeyCode to
zero.

Use constants like vbKeyF1 to match the KeyCode.
 
Thank you;
While this works well for me,AFAIK,there is a way using a macro to do this
globally for all forms.Do you know how to make this macro?
Thanx.
 
The macro must be named AutoKeys.

In the Macro Names column (View menu if you don't see it), enter:
{F1}
for the F1 key, and in the Action column put whatever you want that key to
do.

Of course, some actions will fail if the context is in appropriate. For
example, if you assign to F1 the RunCommand action with the FilterByForm
argument, and then press F1 when the Database window is open, it's not going
to work. Therefore you need to use the Conditions column in the macro to
restrict the cases where the macro action is applied, or else use the
RunCode action to call a function that has error handling so it can recover
from these situations without annoying the user with error messages where
they halt the macro.
 
Its just what i wanted.Thank you.

Allen Browne said:
The macro must be named AutoKeys.

In the Macro Names column (View menu if you don't see it), enter:
{F1}
for the F1 key, and in the Action column put whatever you want that key to
do.

Of course, some actions will fail if the context is in appropriate. For
example, if you assign to F1 the RunCommand action with the FilterByForm
argument, and then press F1 when the Database window is open, it's not
going to work. Therefore you need to use the Conditions column in the
macro to restrict the cases where the macro action is applied, or else use
the RunCode action to call a function that has error handling so it can
recover from these situations without annoying the user with error
messages where they halt the macro.
 
Back
Top