Find out whether a user pressed RETURN ?

G

Gina

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
 
S

Sandra Daigle

Try using the intrinsic constant for the Return Key:

If KeyCode = vbKeyReturn Then
MsgBox "Return"
End If
 
G

Gina

Thanks Sandra ... just tried it and doesn't work either

Gina

Sandra Daigle said:
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.

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
 
S

Sandra Daigle

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.

Thanks Sandra ... just tried it and doesn't work either

Gina

Sandra Daigle said:
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.

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
 
G

Gina

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 said:
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.

Thanks Sandra ... just tried it and doesn't work either

Gina

Sandra Daigle said:
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
 
S

Sandra Daigle

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.

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 said:
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.

Thanks Sandra ... just tried it and doesn't work either

Gina

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
 
G

Gina

on any keyPress it goes into the event apart from the return key...

I was wondering whether my keyboard is still fully working (all key but the
return one not) .. well yes it seems to work
another thing i found out is

I created a totally new textbox put in some keypress code (maybe something
odd about the one it should really work on)
ok ... pressed the return key and it jumped to the next record showing me
the next record in that form ???

ok ... obviously it has to do with the activation order of the various
controls
I set the controls of the form footer not to be 'in order' or row and voila
..... it worked !!!

deary me ... what a silly thing
Thanks for your help and time, Sandra
Gina

Sandra Daigle said:
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.

Thanks Sandra ... just tried it and doesn't work either

Gina

Sandra Daigle said:
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
 
G

Gina

Hi Sandra.

tried what you suggested but after reactivating the order of the controls of
the forms footer
any code for the return key didn't work!!! not with either keypress event or
the keydown event - but any other key worked

wanted to complete the post
thanks again,
Gina


Sandra Daigle said:
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.

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 said:
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

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
 

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