Using ENTER key to move from field to field 
Author Message
 Using ENTER key to move from field to field

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



Thu, 08 Nov 2001 03:00:00 GMT  
 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



Thu, 08 Nov 2001 03:00:00 GMT  
 Using ENTER key to move from field to field
Set Form KeyPreview to True in design property.

Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 then
        SendKeys "{TAB}"
        KeyAscii = 0
    endif
endsub



Thu, 08 Nov 2001 03:00:00 GMT  
 Using ENTER key to move from field to field
I believe I said

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

bestresult.

but thank you for the clarification there, "chato".

~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
> Set Form KeyPreview to True in design property.

> Private Sub Form_KeyPress(KeyAscii As Integer)
>     If KeyAscii = 13 then
>         SendKeys "{TAB}"
>         KeyAscii = 0
>     endif
> endsub



Thu, 08 Nov 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Using the ENTER key to move to the next field

2. Use enter key to move to next field

3. Make Enter key default move to next field?

4. Move Between Fields with "Enter" Key

5. Use enter key to move to next field

6. Enabling Tab Key to move from field to field

7. Moving field data between fields using VB 6 exe

8. How do I get the enter key to automatically tab to the next form field

9. Forms - Text Fields and the Enter Key

10. Tab vs. Enter key for field movement

11. Press Enter key to go to next field

12. Sending the ENTER KEY in one field

 

 
Powered by phpBB® Forum Software