PDA

View Full Version : [SOLVED:] How to get Tab-index from user form in ascending order



raj85
10-07-2014, 02:50 AM
Hello Guys,


I am working on different User forms and I am trying to get tab index of all controls available in user form some forms also have frames and I am creating generic function which will have form as argument But I am facing difficulties as some forms are having frames


I need tab index in ascending order regardless of Frames


EX. 1 user form having 7 control in 4 frames as explained below :
frame 1 -> 2 control
frame 2 -> 1 control
frame 3 -> 3 control
frame 4 -> 1 control
2 control out of frame on the form


I want all controls list with their ascending tab order


Control 7 -> tab index 1
control 3 - tab index 2
control 1 - tab index 3
control 2 - tab index 4
control 4 - tab index 5
control 5 - tab index 6
control 6 - tab index 7
control 8 - tab index 9
control 9 - tab index 8


but due to frames I am facing difficulty


I am having below code




Sub TAB_Index(oFrm As UserForm)Dim iCntr As Integer, ArrTab() As String, oControl As Control, oControl1 As Control




iCntr = 0




For Each oControl In oFrm.Controls
If oControl.Name <> "Frame_Logo" And InStr(1, oControl.Name, "Frame", vbTextCompare) > 0 Then
For Each oControl1 In oControl.Controls
ReDim Preserve ArrTab(1, iCntr)
ArrTab(iCntr) = oControl1.tabindex
iCntr = iCntr + 1
Next oControl1
Else
ArrTab(iCntr) = oControl.tabindex
iCntr = iCntr + 1
End If
Next oControl


END SUB

Bob Phillips
10-07-2014, 03:52 AM
Forget code, select the controls in the tab order that you want, then in the properties window set the TabIndex to 0, they will all increment in the selected order.

raj85
10-07-2014, 05:26 AM
Thank you for the response

Actually I know from property window I can set tab index but I am loading multiple forms one after another so I am also loading user's last selection thus I need this tab index because some controls values are dependent on another controls
Thus I want tab index so I can assign value to controls of form in tab-index order

I can do this but I need to write lot of functions and code I want some easy steps if any.



Forget code, select the controls in the tab order that you want, then in the properties window set the TabIndex to 0, they will all increment in the selected order.

westconn1
10-08-2014, 03:14 AM
x post
http://www.vbforums.com/showthread.php?777851-How-to-get-Tab-index-from-user-form-in-ascending-order

SamT
10-08-2014, 07:36 AM
I would add them to a collection in the order I wanted

or you can



Redim ArrTab(oFrm.Controls.Count)
For Each oControl In oFrm.Controls
If InStr(1, oControl.Name, "Frame", vbTextCompare) = 0 Then
ArrTab(oControl.tabIndex) = oControl.Name
End If
Next oControl
This leaves a few empty slots at the end of ArrTab, but that is easy to deal with.

Jan Karel Pieterse
10-08-2014, 08:10 AM
Forget code, select the controls in the tab order that you want, then in the properties window set the TabIndex to 0, they will all increment in the selected order.

Now that is why I frequent forums: I learn new things! I didn't know this one.

Jan Karel Pieterse
10-08-2014, 08:11 AM
I'm not sure what the tab index has to do with assigning values to the controls?

Aussiebear
10-08-2014, 01:17 PM
Actually I know from property window I can set tab index but I am loading multiple forms one after another so I am also loading user's last selection thus I need this tab index because some controls values are dependent on another controls
Thus I want tab index so I can assign value to controls of form in tab-index order

Isn't the tab index a property of an Object? To my way of thinking you need to be listing Objects from the various forms in a desired order of operation.

raj85
10-09-2014, 02:52 AM
Thank you for the reply,

Let me explain why I need tab-index So you can also help me for any other solution.
Actually, I am having 10 User-forms which fetches data from different Database/API & so on... now I am working on 1 master Form which will have a list-box with all 10 forms names user can select all those and click on update so all Forms will open and download data one after another using user's last selected criteria. I have created generic sub for same and it's working for 5 forms because those forms are having independent text/combo/list box but I am having other 5 forms whose combo-boxes (controls) are dependent on other controls as explained below:

Combo1 values changes as per Combo2 selection. similarly other lot of dependent controls I am having

So when I try to select user's last selected criteria in for each loop, Its first set value for combo1 and then combo2, but combo2 value reset combo1 and I get error. So I thought if somehow I get tab-index then I will write a code to assign values to controls in tab-index order( which is as per dependent controls)

So this is how I got question how to get tab-index for forms which are having frames.

any ideas or suggestions ???

Bob Phillips
10-09-2014, 04:41 AM
Is anyone seriously addressing this when there is another active conversation going on at VBForum?

Jan Karel Pieterse
10-09-2014, 04:57 AM
I guess -since you know the tab order- it is a matter of settings the values to the controls in the right order. What I would do is create a control list in a worksheet and use generic code to populate the controls in that order. The list would be a two column list, col 1 control name, col 2 field name with which to fill the control. Then if you do a
(pseudo-code):

for i = 1 to ControlCount
Me.Controls(TheArray(i,1)).Value=FieldArray(TheArray(i,2))
next
that would ensure your event code takes care of the dependent stuff

Jan Karel Pieterse
10-09-2014, 04:58 AM
@xld: noted!

raj85
10-09-2014, 05:30 AM
Thanks, Jan Karel Pieterse !!! :clap: