Solved

Organize tabindex in vba form with vba code

Posted on 2010-09-21
8
1,485 Views
Last Modified: 2012-05-10
Hi, I have a multipage form with a large number of textboxes and comboboxes. I'd like to assign a specific Tabindex to each one of them so that pressing Tab or Enter the cursor moves from left to right. Presently it moves from top to botton, the way I've copied the boxes in the form.
I've written a vba code which read from a table in a sheet the Textbox name and assigns a Tabindex value, but it does not work. I do not get any error messages but the value are not saved in the tabindex property.
The table starts in a cell named "starttab" and the name of the boxes are written in that column (20 per column). The tabindex value is written 2 columns to the right and columns with the textbox name are 3 columns apart one another.
Again no error messages, debug works fine, but the tabindex value are not upgraded.
Option Explicit

Dim sBoxName As String

Dim iColumnOffset As Integer

Dim iRowoffset As Integer

Dim iTabOrder As Integer



Sub taborder()

For iColumnOffset = 0 To 33 Step 3

For iRowoffset = 1 To 20

With wksMenuSheet.Range("starttab").Offset(iRowoffset, iColumnOffset)

sBoxName = .Value

iTabOrder = .Offset(0, 2)

 FPortfolioInput.Controls(sBoxName).TabIndex = iTabOrder

End With

Next iRowoffset

Next iColumnOffset

MsgBox ("Done")

End Sub

Open in new window

0
Comment
Question by:yuppydu
  • 5
  • 3
8 Comments
 
LVL 11

Expert Comment

by:jkpieterse
ID: 33731990
You are setting the tabindexes during runtime, to an instance of your userform in memory. Instead, you should be setting the tabindex at design time, using the "Microsoft Visual Basic For Applications Extensibility" library.

Dim oCtl as Control
For Each oCtl in ActiveWorkbook.VBProject.VBComponents(YourFormName).Designer.Controls
oCtl.TabIndex=GetIndexFromSomewhere
Next
0
 
LVL 4

Author Comment

by:yuppydu
ID: 33731998
I've tried something like that but I get an error at the for each.... command.
Do I have to attach a library?
0
 
LVL 4

Author Comment

by:yuppydu
ID: 33732013
My table for textbox names and tabindex value is organized like this. How do i make the cursor go down the first column to read the texbox name and then move right 2 columns to read the tabindex value? Is my with and for routine valid?
excel-table.gif
0
 
LVL 11

Expert Comment

by:jkpieterse
ID: 33732079
Tools, references, check this one: Microsoft Visual Basic For Applications Extensibility

Sub Tabs()

    Dim oCell As Range

    For Each oCell In Range("A2:A21")

        With ActiveWorkbook.VBProject.VBComponents(YourFormName).Designer

            .Controls(oCell.Value).TabIndex = oCell.Offset(, 2).Value

        End With

    Next

End Sub

Open in new window

0
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!

 
LVL 4

Author Comment

by:yuppydu
ID: 33732155
it's giving me Type mismatch in  With ActiveWorkbook.VBProject.VBComponents(fportfolioinput).Designer
0
 
LVL 4

Author Comment

by:yuppydu
ID: 33732175
this is just one of the columns. The full table for textboxes looks like this, and I have 9 more pages in the form. This is why I'm looking for a code to do it. Manually would be a nightmare
excel-table.gif
0
 
LVL 11

Accepted Solution

by:
jkpieterse earned 500 total points
ID: 33732483
Put the form's name between quotes.

About the table:

You could either just reformat the table so all controls are beneath each other and the code I gave can read the table. Or you can add a bunch of lines to the code like so:

.Controls(oCell.Value).TabIndex = oCell.Offset(, 2).Value
.Controls(oCell.Offset(,3).Value).TabIndex = oCell.Offset(, 5).Value
.Controls(oCell.Offset(,6).Value).TabIndex = oCell.Offset(, 8).Value
.Controls(oCell.Offset(,9).Value).TabIndex = oCell.Offset(, 11).Value
.Controls(oCell.Offset(,12).Value).TabIndex = oCell.Offset(, 14).Value
'.........
0
 
LVL 4

Author Closing Comment

by:yuppydu
ID: 33732536
Thanks, it seems to work fine, few mistakes in my table of values but that's my issue. Your code it perfect. That's going to save me a lot of time, I have more than 500 textboxes tabindex
0

Featured Post

Highfive Gives IT Their Time Back

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

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

707 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

20 Experts available now in Live!

Get 1:1 Help Now