Tabindex

  • Thread starter hotrod1952 via AccessMonster.com
  • Start date
H

hotrod1952 via AccessMonster.com

I have form with several controls. When a data is input into the control I am
setting the next control visible and setting focus to it. what is the best
way in code to determine the tabindex of the latest visible control. example
control1 after update makes control 2 visible and sets focus to it. Form
entry person moves mouse to control 1. On a command button (no tabstop on
this one) I need to find that conrol 2's tabindex is the current highest
position not control 3 .... which is not yet visible.
 
A

Allen Browne

I don't think you can read this directly.

You would need to loop through each Control in Me.Controls, reading the
TabIndex of each (handling the controls that don't have a TabIndex), and
testing the Visible and Enabled properties to see if they can take focus,
and possible the TabStop to see if the control gets focus as you tab
through. Place the control names in an array (using the TabIndex as the
array index), and you have the info you need.
 
D

Dirk Goldgar

hotrod1952 via AccessMonster.com said:
I have form with several controls. When a data is input into the control I
am
setting the next control visible and setting focus to it. what is the best
way in code to determine the tabindex of the latest visible control.
example
control1 after update makes control 2 visible and sets focus to it. Form
entry person moves mouse to control 1. On a command button (no tabstop on
this one) I need to find that conrol 2's tabindex is the current highest
position not control 3 .... which is not yet visible.


I'm not entirely sure I understand you , but maybe you can adapt this
function to your purpose, or at least use it as a demonstration of the
properties you'll have to work with.

'----- start of code -----
Function NextInTabOrder(StartCtl As Access.Control) As String

' Returns the name of the next active control in the tab order,
' if possible. Returns a null string if there isn't one.

Dim astrControlNames() As String
Dim obj As Object
Dim ctl As Access.Control
Dim intI As Integer

On Error Resume Next
'to ignore errors we expect to raise

Set obj = StartCtl.Parent

ReDim astrControlNames(obj.Controls.Count)

' Build a list of available controls indexed by TabIndex.
' We aren't interested in controls that are invisible,
' disabled, not a tab stop, or not in the same section
' as StartCtl.
For Each ctl In obj.Controls
With ctl
If .Section = StartCtl.Section Then
If .Visible = True _
And .Enabled = True _
And .TabStop = True Then
astrControlNames(.TabIndex) = .Name
End If
End If
End With
Next ctl

Set obj = Nothing

' Loop forward through the list
For intI = StartCtl.TabIndex + 1 To UBound(astrControlNames)
If Len(astrControlNames(intI)) > 0 Then
NextInTabOrder = astrControlNames(intI)
Exit Function
End If
Next intI

' If we didn't find one, start at the beginning of the list.
For intI = 0 To StartCtl.TabIndex - 1
If Len(astrControlNames(intI)) > 0 Then
NextInTabOrder = astrControlNames(intI)
Exit Function
End If
Next intI

' If we get here, there's no available control.
Exit Function

End Function
'----- end of code -----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top