Solved

moving through components with TAB

Posted on 2003-11-13
13
467 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:zolpo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +2
13 Comments
 
LVL 15

Assisted Solution

by:SRigney
SRigney earned 100 total points
ID: 9739194
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.
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 9739213
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.
0
 
LVL 1

Author Comment

by:zolpo
ID: 9739299
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:ajexpert
ID: 9739362
This doesn't disables the mouse anyway.  Can you tell us what you did exactly
0
 
LVL 1

Author Comment

by:zolpo
ID: 9739424
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
0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 100 total points
ID: 9739587
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
0
 
LVL 1

Author Comment

by:zolpo
ID: 9739684
Hi,
Thanx, it works now,
as to my other q, how can I use Enter key to do the same as Tab?
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9739731
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
0
 
LVL 28

Assisted Solution

by:vinnyd79
vinnyd79 earned 100 total points
ID: 9739763
or use sendkeys to send a tab

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then SendKeys "{Tab}"
End Sub
0
 
LVL 15

Expert Comment

by:SRigney
ID: 9739769
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

0
 
LVL 1

Author Comment

by:zolpo
ID: 9739857
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!!!!
0
 
LVL 15

Expert Comment

by:SRigney
ID: 9740563
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
0
 
LVL 1

Author Comment

by:zolpo
ID: 9758253
Hi,
Thanx guys, u all helped me a lot!!!!
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question