
Using ENTER key to move from field to field
You need to use SendKeys, and you need to 'eat' the keystroke to avoid the
beep, like this:
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys "{TAB}"
KeyAscii = 0
End If
End Sub
Notice this is the KeyPress event for a textbox control array. It works
better if you can have a single event where to place your code. Or, you can
set the form's KeyPreview property to True, and place the code in the Form's
KeyPress or KeyDown/Up events. You might want to experiment for the best
result.
Also, note that this will not work if you have a command button on the form
whose Default property is set to True, because that will cause all Enter
keystrokes to be eaten by the button and neither the form nor any other
control on it will see it.
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please post/reply to the newsgroup(s) so
that everyone can benefit from the discussion.
Regards,
Klaus H. Probst, MCP
ICQ: 22454937
The VB Box: http://members.xoom.com/kprobst/
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quote:
> I'm trying to use the ENTER key to move from field to field and it works
OK to
> use the following on the KeyPress function:
> If KeyAscii =13 then
> text1.setfocus
> end if
> But everytime a beep sounds, and that can get annoying.
> How can I make an assignment that the ENTER key works like the TAB key
within
> the current form.
> Using:
> IF KeyAscii =13 then
> KeyAscii = 9
> end if
> doesn't work, although
> IF KeyAscii =13 then
> KeyAscii = 8
> end if
> works correctly and assigns the BACKSPACE key function to the ENTER key
(at
> least for the current field).
> Where is my thinking off? Any help would be greatly appreciated.
> Juergen Amling
> Reisende soll man nicht aufhalten