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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Goto control with tabindex 0

Status
Not open for further replies.

MikeCDPQ

Technical User
Sep 11, 2003
173
CA
Hi everyone,

This should be so simple. I have different continuous forms. The controls ("columns") are not all in the same order. In need to be able to enter the form and specify the tab index number of the control I want to go to.

Just like: docmd.gotocontrol("controlname")

I need: docmd.gotocontrol(tabindex (1)).

That does not work. Any ideas ?

Thanks
 
You could loop through the Controls collection and when a control has a tabindex of 0, you could set focus to it.

However, you will have to check the control type first as not all controls have a tabindex.

Code:
For Each ctl In Controls
   If ctl.ControlType = acCommandButton Then
      If ctl.TabIndex = 0 Then
         ctl.SetFocus
         Exit Sub
      End If
   End If
Next

**********************************
There is more than one way to skin a cat...but who wants a skinned cat?
 
or, in the line of what Ormsk said,
using the controls collection

docmd.gotocontrol Me.Controls(4)

I may be wrong, does the Controls Index, correspond
with the tab index?
 
Thanks to both of you.

I opted for Zion7's solution and added in the form section of the control:

FirstFieldOnForm = Forms(CurrentFormName).Section(0).Controls(1).Name


To answer you question, it seems that Control index is the absolute position of a control on a form whereas Tab Index can be modified by users by changing the tab order.

Using ... Controls(0) did not give me the wanted control name whereas using ... Controls(1) did every time.

Thanks a bunch.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top