moving through components with TAB

Hi,
I'm working with VB6,
I have a form with text boxes, buttons and radio buttons,
I want the user to be able to move from one component to another by clicking the Tab or Enter,
right now, when clicking Tab it moves, but not in the order I want.
How can I change the order the Tab key moves on the components?

thanx
LVL 1
zolpoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SRigneyCommented:
Each control has a TabOrder property.   0 is the lowest.

Go through each control and set the correct tab order.
A quick way to do it is to go through all controls starting with the last one in reverse order, and set the tab order for each to 0.

When you set the second to last one to 0 the last one gets changed to 1 by VB.

The problem is that when you put the controls onto your form, the tab order gets set to the order that the controls were added to the form.
ajexpertCommented:
Hi,
  You need to set the TabIndex property of each control.  TabIndexes should be start from where you want to get focus and increase it by 1.
zolpoAuthor Commented:
Hi,
I did what u suggested, but now, after I move with the TAB key,
the mouse is disabled, and I cant move through the components with the mouse, but only with the Tab key
Thanx
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

ajexpertCommented:
This doesn't disables the mouse anyway.  Can you tell us what you did exactly
zolpoAuthor Commented:
Hi.
I changed the TabIndex like u said,
I clicked with the mouse on each component and changed the tabIndex to the number i wanted, I didnt change all of the components' tabindex, only those I needed to change
thanx
Arthur_WoodCommented:
when you change the Tabs of selected controls, you MUST do this in the REVERSE order of how you want to navigate through the controls.

Every control placed on a page gets a DEFAULT tabIndex value, which is the ORDER in which they were ORIGINALLY placed on the page.  So the First control placed on the form gets 0, the next one gets 1 and so on. And it is NOT possible for two controls to have the same TabIndex.

When you change the TabIndex of any control, all of the controls that have indexes the same OR higher that the one you are re-indexing, have their tabIndexes changed (increased by 1) to make room for the control that you are assigning the new TabIndex for.  Thus, you make sure that the controls get the TabIndex that you want them to have, Start with the Control that you want to be LAST, and set its TabIndex to 0, then go to the control that you want to be NEXT_TO_LAST, and again set ITS tabindex to 0 (yes, I said set that one to 0 - the one that you previous set to 0 will be changed to TabIndex 1) continue this process until you get to the Control that you want to be FIRST, and again set its TabIndex to 0.  Now the TabIndexes will be 0...N in the CORRECT ORDER!!!!.

AW

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zolpoAuthor Commented:
Hi,
Thanx, it works now,
as to my other q, how can I use Enter key to do the same as Tab?
vinnyd79Commented:
You could set the focus to the next control in the KeyPress Event:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
    Text2.SetFocus
End If
End Sub
vinnyd79Commented:
or use sendkeys to send a tab

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then SendKeys "{Tab}"
End Sub
SRigneyCommented:
Another method to prevent code changes if you change the tab order again is to use

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
    SendKeys "{TAB}"
End If
End Sub

zolpoAuthor Commented:
Hi,
Thank guys!!!!
one more thing, when the form loads, I want the cursor to be in a text box
indexed 0,
right now, I need to click the mouse inside the textbox to see the cursor
THANX A LOT!!!!
SRigneyCommented:
Try
If TextBox1.Visible Then TextBox1.SetFocus

I find it best to put this in the Form1_Activate event

The only possible problem is if the form isn't the only form, then I use a little work around to keep the focus from going back to the first field everytime that form become the focus.

I'm winging it with this code the declaration will be a little different.
Sub Form1_Activate
Static FirstTime as Bool = True
   If FirstTime Then
      If TextBox1.Visible Then
         TextBox1.SetFocus
      End If
      FirstTime = False
   End If
End Sub
zolpoAuthor Commented:
Hi,
Thanx guys, u all helped me a lot!!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.