• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 149
  • Last Modified:

Return Key as Tab Key

Is there a way to use the Return Key instead of the Tab key to move to the next control without having to trap the key with the individual control events.

THANKS FOR YOU ASSISTANCE

Paul
0
Paddyo
Asked:
Paddyo
1 Solution
 
alokanantCommented:
As far as I know there is none.
A good idea is to use a control array. This simplifies the task, so that the code can be written only once for each type of control.

hth
alok.
0
 
GunsenCommented:
Private Sub Form_KeyPress(KeyAscii As Integer)
  If KeyAscii = 13 Then
    SendKeys Chr$(9), True
    KeyAscii = 0
  End If
End Sub
0
 
GunsenCommented:
Ans also, the form's KeyPreview must be enabled (true)...
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
caraf_gCommented:
Let me ask you a question.... WHY? Your users are running your product under windows. In windows the TAB key is used to move from one control to the next. Educate your users.
0
 
paul_tsekovCommented:
Hi, VBfan

The easier way for not writing much code in each Key_Pressed event sub is
using the indexed array of controls.

For example when you put a textbox on your form you name it
--
 Name Property : MyText
--

Now make the Index property 0
--
Index Property : 0
--

Now , you want to put another textbox on the form. So just name it with the same name:

--
 Name Property : MyText
--

Make it's index property 1
--
Index property : 1
--
And so on put TextBoxes names MyText
  and with ascending Index property

So now you have an array of indexed TextBoxes , each with the same name, but the different Index.
  Lets say we have made 10 TextBoxes
each with
 Name : MyText
 Index : i
  i changes from 0 to 9 for the different TextBoxes

So in your form's code module you should have the sub:

Private Sub MyText_KeyPressed(Index As Integer, KeyAscii As Integer)
' Here you could put the code:
  if KeyAscii=13 then
    Select Case Index  
      Case 0 to 8
        MyText(Index+1).SetFocus
      Case 9
        MyText(0).SetFocus
    End Select
  End If
End Sub

So that code should work by changing the focus to the next TextBox each time.
 When you've reached the last TextBox
 and then press Enter , the focus should go to the first TextBox.

  In case you have another ComboBox indexed group of ComboBoxes after the TextBoxes group, in the row below Case 9, instead of MyText(0).SetFocus you could write MyCombo(0).SetFocus
    and so on ...

Remember,
   try making groups of idetical items, using the indexed arrays.
  That surely makes life easier!!!

             Pavel Tsekov
      email : paul_tsekov@yahoo.com
 
 
 
0
 
alokanantCommented:
Hi Paul,

That's a good elaboration on my comment!

alok.
0
 
amebaCommented:
I agree with caraf_g's comment. Tab key is standard for Windows. It also increases productivity (forces users to use two hands for typing)

BTW,
    Select Case Index  
      Case 0 to 8
        MyText(Index+1).SetFocus
      Case 9
        MyText(0).SetFocus
    End Select
can be replaced with one line:
    MyText((Index+1) Mod 10).SetFocus
0
 
PaddyoAuthor Commented:
One of the reasons I wish to use the Return Key as well as the TAB key is that where there is a lot of numeric input, i.e. an accounting system, the numeric keypad is used. The Tab key is on the other side of the keyboard!! It is quicker to use the Enter Key.

Also - TAB maybe standard but customers are customers - they pay my wages.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now