Here's a subroutine that I have used to do this:
' **********************************
' * 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" AND MUST BE VISIBLE AND MUST BE ENABLED, 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) And _
xctl.Visible = True And xctl.Enabled = True 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