Solved

moving through components with TAB

Posted on 2003-11-13
13
464 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 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now