Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

moving through components with TAB

Posted on 2003-11-13
13
Medium Priority
?
474 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
  • 5
  • 3
  • 2
  • +2
13 Comments
 
LVL 15

Assisted Solution

by:SRigney
SRigney earned 400 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 400 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 400 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

782 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