Manipulating Tab Index on Forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a programmatic method of manipulating the tab stop index? I want to
be able to create a function or event that allows me to go to the "next" tab
stop without having to specify the name of the control. For example -
If x Then
Do.cmd gotonexttabstop
End If

Thanks...David
 
Something like this subroutine, perhaps?
----

' **********************************
' * Sub MoveFocusToNextControl *
' **********************************

Public Sub MoveFocusToNextControl(xfrmFormName As Form, _
xctlCurrentControl As Control, _
xblnOnlyTabStopYes As Boolean)
' *** THIS SUBROUTINE MOVES THE FOCUS TO THE NEXT
' *** CONTROL IN THE TAB ORDER.
' *** IF xblnOnlyTabStopYes IS TRUE, THEN THE NEXT CONTROL
' *** MUST HAVE A TAB STOP VALUE OF "TRUE",
' *** ELSE THE SUBROUTINE GOES TO THE NEXT CONTROL.
' *** NOTE: THIS SUBROUTINE WILL NOT "CYCLE BACK" TO
' *** TAB INDEX OF 0, SO DO NOT USE THIS SUBROUTINE
' *** IF THERE IS NO CONTROL CAPABLE OF RECEIVING THE
' *** FOCUS IN THE TAB ORDER SEQUENCE AFTER THE
' *** CURRENT CONTROL!!!!!
'Ken Snell - May 26, 2005

Dim xctl As Control
Dim lngTab As Long, lngNewTab As Long

On Error Resume Next

' Move focus to the next control in the tab order (if that control has a Tab
Stop
' property of True)
lngTab = xctlCurrentControl.TabIndex + 1

MyLoopLabel:
For Each xctl In xfrmFormName.Controls
lngNewTab = xctl.TabIndex
' An error will occur if the control does not have a TabIndex property;
' skip over those controls.
If Err.Number = 0 Then
If lngNewTab = lngTab Then
If xctl.TabStop = True Or xblnOnlyTabStopYes = False Then
xctl.SetFocus
Exit For
Else
lngTab = lngTab + 1
GoTo MyLoopLabel
End If
End If
Else
Err.Clear
End If
Next xctl
Set xctl = Nothing
Err.Clear
End Sub
 
Back
Top