How to get Tabindex from userform

rajkavikumar

New Member
Joined
Oct 2, 2012
Messages
20
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 proper tab index 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

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

but due to frames I am facing difficulty:confused::confused:

I am having below code
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) = oControl.Name & iCntr
            iCntr = iCntr + 1
        Next oControl1
    End If
Next oControl

END SUB
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

mohan.pandey87

Board Regular
Joined
Sep 14, 2012
Messages
146
Here you go:

Code:
Sub LMP_Test(ByVal usrFrom As UserForm)


    Dim ctrl        As Control
    Dim frmCtrl     As Control


    For Each ctrl In usrFrom.Controls
        If TypeName(ctrl) = "Frame" Then
            For Each frmCtrl In ctrl.Controls
                Debug.Print frmCtrl.TabIndex
            Next frmCtrl
        Else
            Debug.Print ctrl.TabIndex
        End If
    Next ctrl


End Sub
 

rajkavikumar

New Member
Joined
Oct 2, 2012
Messages
20
Thank mohan.pandey87,

For your quick reply,
but if I do by this way then every frame has its own tab-index as shown below
frame 1 -> 2 control will have tab index 0 to 1
frame 2 -> 1 control will have tab index 0
frame 3 -> 3 control will have tab index 0 to 2
frame 4 -> 1 control
will have tab index 0

but I need all controls' tab-index in ascending order that's the challenge
and even frames also have their own tabindex so first I need to check their tabindex order and then I need to access each frame in ascending order and then get all controls' tab-index from that each frame.

it gonna be huge code I need to do it easily
is there any way you know to do it easily ???
 

Watch MrExcel Video

Forum statistics

Threads
1,122,964
Messages
5,599,069
Members
414,281
Latest member
Engjamal2021

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top