Re: Find out whether a user pressed RETURN ?

From: Sandra Daigle (Invalid_at_KeepYourSpam.org)
Date: 03/16/05


Date: Wed, 16 Mar 2005 09:52:05 -0500

Gina,

You need to use the KeyDown event for this - here's what the help says : "If
a keystroke causes the focus to move from one control to another control,
the KeyDown event occurs for the first control, while the KeyPress and KeyUp
events occur for the second control". So your Return keystroke shows up in
the keypress event of the next control (you can also pick it up in the
Keypress event of the form).

-- 
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.
Gina wrote:
> Sandra.
>
> this is what i#ve got there:
>
> Private Sub txtNummernBlatt_KeyPress(KeyAscii As Integer)
> Debug.Print "Ascii " & KeyAscii
>    If KeyAscii = 13 Then
>        cmdNummernBlatt_Click
>    End If
>
> End Sub
>
> and as I said before it reacts on any kind of keypress but not :( :(
> on the return one
>
> ???
> Gina
>
> "Sandra Daigle" <Invalid@KeepYourSpam.org> schrieb im Newsbeitrag
> news:OJi6BBjKFHA.1176@TK2MSFTNGP15.phx.gbl...
>> What does happen? Have you tried stepping through the code or
>> putting in a debug.print or msgbox to see what happens (ie whether
>> it gets into the code after the if)?
>>
>> --
>> Sandra Daigle [Microsoft Access MVP]
>> Please post all replies to the newsgroup.
>>
>>
>> Gina wrote:
>>> Thanks Sandra ... just tried it and doesn't work either
>>>
>>> Gina
>>>
>>> "Sandra Daigle" <Invalid@KeepYourSpam.org> schrieb im Newsbeitrag
>>> news:ORUx01iKFHA.2604@TK2MSFTNGP10.phx.gbl...
>>>> Try using the intrinsic constant for the Return Key:
>>>>
>>>>     If KeyCode = vbKeyReturn Then
>>>>         MsgBox "Return"
>>>>     End If
>>>>
>>>> --
>>>> Sandra Daigle [Microsoft Access MVP]
>>>> Please post all replies to the newsgroup.
>>>>
>>>>
>>>> Gina wrote:
>>>>> Hi all.
>>>>>
>>>>> on a special textfield i would like the user to be able to just
>>>>> press 'return' in order to set a command button the default one.
>>>>>
>>>>> _____________________________
>>>>> Private Sub txtX_KeyDown(KeyCode As Integer, Shift As Integer)
>>>>>    If (KeyCode = 13) Then
>>>>>        cmdX_Click
>>>>>    End If
>>>>> End Sub
>>>>>
>>>>> Private Sub txtX_KeyPress(KeyAscii As Integer)
>>>>>    If KeyAscii = Chr(13) Then
>>>>>        cmdX_Click
>>>>>    End If
>>>>> End Sub
>>>>> ______________________________
>>>>>
>>>>> code reacts on any key but not on the return button :(
>>>>> any idea as to how & perhaps where . . . put some right bits ?
>>>>>
>>>>> thanks
>>>>> Gina