Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tab Index Property

Status
Not open for further replies.

markphsd

Programmer
Jun 24, 2002
758
US
I've been trying to figure this out for a while.

I have to set the tab index of about 60 or 70 controls on a form.

I have a sub that runs when the form loads, i've also tried it after the form is open:

It goes like this:

option explicit
private mlTabInit as integer

Private Sub InitTabIndex()

On Error GoTo eh:

mlTabInit = 0
FullName.TabIndex = 0
CompanyName.TabIndex = GetNextTab
Title.TabIndex = GetNextTab
Phone.TabIndex = GetNextTab
Fax.TabIndex = GetNextTab
CellPhone.TabIndex = GetNextTab
BusinessPhone.TabIndex = GetNextTab

etc....
exit sub

eh:

end sub

Private function GetNextTab() as integer
mlTabInit = mlTabInit + 1
GetNextTab = mlTabInit
end function

But it doesn't work. Stepping through each update of the tab index property on a control shows me that the actual index is not set.

Any ideas?

Mark P.
Providing Low Cost Powerful Point of Sale Solutions.
 
have you ever considered steping through the controls collection on your form?

e.g.

for each ctrl in me.controls
if ctrl.controlType = 106 then '106 is a text box...
ctrl.tabindex = getnexttab
endif
next ctrl

have you checked wether the controls have the tabstop property set to yet?

--------------------
Procrastinate Now!
 
My guess would be that your "Properties" set it to one thing each time you go into design view. Once you run your sub it changes it to your new values.

try running a message box to show you the tabindex after the routine runs.

Code:
Private Sub Command6_Click()
MsgBox "Text 0 = " & Text0.TabIndex & ", Text 2 = " & Text2.TabIndex & ", text 4 = " & Text4.TabIndex

Text0.TabIndex = 0
Text2.TabIndex = 2
Text4.TabIndex = 1

MsgBox "Text 0 = " & Text0.TabIndex & ", Text 2 = " & Text2.TabIndex & ", text 4 = " & Text4.TabIndex
End Sub
 
Crowley16:
What i'm doing is what you are doing, only i'm telling the form what the index should be for specific controls

CaptainD:
Stepping through code is more useful as i get a update as soon as the item's property is set. But it's essentially the same idea.

Regardless I'm assigning it at a value, and it gives me no error, but the value is not saved to the control.

I'd suggesting trying this if you have no specific experience with this property.

Mark P.
Providing Low Cost Powerful Point of Sale Solutions.
 
Crowley,
You:
"have you ever considered steping through the controls collection on your form?"
Me:
"Stepping through each update of the tab index property on a control shows me that the actual index is not set. "


Mark P.
Providing Low Cost Powerful Point of Sale Solutions.
 
Wtih the one I posted, (stepping through the code or reading the two message boxes) the tab index changes but the property does not. meaning that in design mode I have a different tab index then I do at run time.

When I run the form the tab index is in the order I created at design time, click the command button and it changes to the new order. And that was also tested by tabing through the controls before the click event and then after.
 
CaptainD,

Although I think I understand what you are saying. I don't see what the difference between what your code is doing and what my code is doing is.


This code runs everytime the form is loaded.

Mark P.
Providing Low Cost Powerful Point of Sale Solutions.
 
My point is, or my guess is, your code is doing what it is supposed to do.

In design view the "Properties" are set by the properties "control", then when you run the code, they are then reset by your code. My example was just to test to see if at runtime they were indead setting to the desired values. In my example they are.

My question now is, how to change the property on a perminant basis? which I gather is where the problem is.
 
Oh, i don't care about a permanent basis. I just want them to change at runtime.

For some more info on why this is the case:

This is a contact form, it stores info on different kinds of contacts, such as doctors, patients, suppliers etc.

There are different controls for the different contact types. So it's required that the tab index change to suit the contact type.

Mark P.
Providing Low Cost Powerful Point of Sale Solutions.
 
How are ya markphsd . . .

Curious this! . . . [blue]How are you predetermining what the tab order should be?[/blue]
or
[blue]Whats changing the order that makes this necessary?[/blue]

In either case, [blue]if you want the changes to be permament[/blue] you have to make the changes in [blue]form design view[/blue] and save before you close the form!

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
1. Permanency would be contrary to what is required.

2. The form has too many controls to use that Tab Editor.

2 Examples would be:

For general discussion:
What's determining this?

There's three columns, the middle column of fields that has information specific to the contact type. Sometimes these are hidden and sometimes they are visible. I've just found that the easiest method to set the tab index would be to use the aforementioned code(except it doesn't work).

The form's formating is done by code, so this would be inline with how it's designed.

Mark P.
Providing Low Cost Powerful Point of Sale Solutions.
 
OK markphsd . . .

Understood! . . .

[blue]Hidden fields are skipped in the tab order[/blue] so there should be no need to reset the index!

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
My thoughts...

I just got home and it's 3 am. That's #1.

Secondly. I would refer back to the last part of the last post. I prefer to do this in code because that is where the formating is being done. If i was doing the formating via drag and drop of controls, then i would stick with that.

I'm going to actually take a bunch of steps backwards and start with a new form, drop some controls and do some testing. I think it will better identify where the problem really originates.

Mark P.
Providing Low Cost Powerful Point of Sale Solutions.
 
markphsd . . .

Formatting has nothing to do with the tab order! [surprise]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Okay,

I figured out what the problem is. But i still require a solution.

The code works fine. As it should, but only when i'm not using it one controls in a tab control.

So i've got to figure that out. Anyone have any ideas?

To reproduce the problem. Place 20 controls on a form and try to change the tab properties through code. Like, reverse it or something. I have controls that have been added over time so their order is completely different from the index value.

As a note: when using the code I get through about 5 controls and then it breaks down. But only when the controls are on the TabControl.


Mark P.
Providing Low Cost Powerful Point of Sale Solutions.
 
My guess would be that the tab control( or one of the other controls), is a control, and it does not have a tabindex to set.
(check the properties to see)
So you need to come up with a way to say:

If ctrl = TabControl skip setting the tab index and move on to the next ctrl.

If I get time later, I'll take a look at it but that is my initial thought.
 
The tab control can be set. The controls within it can be set.
But it doesn't work properly. Test it with more than 20 controls. I know what I'm doing, all I'm doing is looking for the work around now.

Actually, I've come to a solution, however it doesn't use the tab control anymore.

Mark P.
Providing Low Cost Powerful Point of Sale Solutions.
 
A tab control has its own tab order, so it would need to be numbered separately. How about numbering the form controls by testing the name of the parent:

[tt]If ctl.Parent.Name = Me.Name Then[/tt]

Then numbering the tab control pages:

Code:
For Each pge In Me.TabCtl0.Pages
    mlTabInit = 0
   'Very roughly, you probably require 
   'more sophistication
    For Each ctl In pge.Controls
        ctl.TabIndex = GetNextTab
    Next
Next
 
Would you mind posting your "work around" so others can see you solution?
 
Remou,

Sounds like you know what you are talking about. Only thing is, I'm not sorting any control outside of the Tab Page.

So even if I used your code, all of the controls I'm sorting would still be within that loop.

CaptainD :
My workaround was the not use the Tab Control for those controls. Not a solution, except for me on this one instance.

I only needed to sort the controls on the first page. So pulled them all off and put them in the background. When they are being used I just hide the tab control.

This needs to be resolved though because I'll probably end up adding a lot more controls that do need to be sorted.


Mark P.
Providing Low Cost Powerful Point of Sale Solutions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top