| | |
|
|
|
Lost Focus/Last Key ENTER ? |
| message from Dave Ruhl on 6 May 2004 |
Hello, I want to know how I can tell if the ENTER key was
hit to make a control lose focus (as opposed to TAB or a
mouse click). I've tried the OnKeyPress event, but it
doesn't get triggered by the ENTER key. I've also tried
the OnKeyDown event. It does catch the ENTER key, but
leaves my textbox with a NULL value, even if data appears
to be in it.
So, there doesn't seem to be a way to trap the ENTER key
without losing the data in my control. Can this be
done ? Thanks!
|
| Albert D. Kallal replied to Dave Ruhl on 6 May 2004 |
The above is not my experience. Something is wrong, as you should be able
use the On Key Down event.
A few things:
You can change the focus by using the keydown event, but you need to
remember a few things:
The before update..and after update events still need to fire.
The Enter key, or the tab key is STILL GOING TO be processed. So, if you
move the focus some where else..then the Enter key will then fire..and try
to move. In other words..be careful..as the key you pressed is STILL going
to take action. So, if you move the focus with the key down ..then the enter
key still is firing. The solution usually is to send the keypress into a
black hole..and NOT let ms-access see it. Here some key down code that
should work:
Private Sub CutName_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyReturn
' if user hits return, lets move to customer field
KeyCode = 0 ' VERY imporant to kill the keypress!
Me.Customer.SetFocus
Case vbKeyTab
KeyCode = 0
Me.TakenBy.SetFocus
End If
End Sub
Of course...you don't copy the Sub name above. However, try killing the
keypress...as you MUST remember if you change the behaviour or set the
focus...access will STILL process the keypress. By using KeyCode = 0, then
access does NOT process the key.
|
| Dave Ruhl replied to Albert D. Kallal on 6 May 2004 |
Thanks Albert, I will try that. I figured I must be
missing something. Thanks!
appears
you should be able
you need to
fire.
processed. So, if you
then fire..and try
pressed is STILL going
down ..then the enter
keypress into a
down code that
Integer)
field
keypress!
try killing the
behaviour or set the
KeyCode = 0, then
|
|
Archived message: Lost Focus/Last Key ENTER ? (Microsoft Access)