Keydown hierarchy and best practices

A

Atlas

Hi everyone,
I was looking for an explaination about the Keydown event queue, trying to
understand if there's a wise Keydown event management on forms/controls, alà
what has to be done formwide it is stuffed into the form's keydown event
handler, and manage few exceptions int the control's keydown event handler.

Unfortunatelly it looks that code is executed in both the cases, in the
control and the form.

So my second question is if there is a way to executed control's code first,
then form's code, eventually aborting code execution in the control's
handler (avoiding form's keydown event execution).

So I was wondering if there's any best practice managing "cascaded" keydown
events in a form->controls fashion.

Particullarly what I would like to do is to manage the ESCape key as a
default UNDO & "close window" key, application wide.

This is how it should work:

On a form if users presses Escape:

1) Form is clean->docmd.close

2) Form is clean, current control is dirty->Undo control changes

3) Form is dirty, current control is clean->Ask if user wants to discard
changes, if so undo form and exit

4) Form is dirty, current control is dirty-> same as point 2.


The goal is minimizing code!


Any hint appreciated

Regards
 
S

Stefan Hoffmann

hi Atlas,
Unfortunatelly it looks that code is executed in both the cases, in the
control and the form.
The key pressed is processed first in the Form event and then in the
control event, unless you set KeyCode=0 in the Form event.

mfG
--> stefan <--
 
A

Atlas

The key pressed is processed first in the Form event and then in the
control event, unless you set KeyCode=0 in the Form event.

So.... can I detect what control has focus? If so I could stuff all the code
in the Form's onKeydown event handler..... check what control has focus and
see if it has changed, if so undo....and so on....
 
S

stefan hoffmann

hi,
So.... can I detect what control has focus? If so I could stuff all the code
in the Form's onKeydown event handler..... check what control has focus and
see if it has changed, if so undo....and so on....
You can use Screen.ActiveControl and Screen.PreviousControl, but i'm not
sure if it works in all cases.

Private Sub Form_KeyPress(KeyAscii As Integer)

On Local Error Resume Next

Caption = ""
Caption = Str(KeyAscii) & " "
Caption = Caption & Screen.ActiveControl.Name

End Sub

Seems to work...

mfG
--> stefan <--
 
S

Stefan Hoffmann

hi,
BTW what do you think about my escape\undo approach?
It is a nice idea, but Access as appplication host has its own default
behaviour standards. I think it is better for users to let them learn
the Access way, so they only have to learn to use one programm.


mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top