Tab Order


Changing the Tab Order of Form Fields

Word automatically decides the tabbing sequence for your form fields.
Lets consider that you have put your form fields into a table, you might want your users to tab through all the fields in column 1, then column 2, then column 3; whereas by default, they will tab through the formfields in row 1, then row 2, then row 3.
You can get around this by using a macro although it does mean that you will not be able to use the mouse to select which form field you want to change.
A userform in this situation should be used.
The UserForm code could fill in the document form (with or without using form fields in the document); and the tab-order of UserForm controls is very easy to set.


Creating an OnExit macro for each form field

Always give your bookmarks meaningful names.

Option Explicit 

Sub ExitBetter1()
    ActiveDocument.Bookmarks("Better3").Range.Fields(1).Result.Select
End Sub

Sub ExitBetter2()
    ActiveDocument.Bookmarks("Better1").Range.Fields(1).Result.Select
End Sub

Sub ExitBetter3()
    ActiveDocument.Bookmarks("Better2").Range.Fields(1).Result.Select
End Sub


Assign a single OnExit macro to all your form fields

If you have a lot of form fields you might find it easier to create a single macro to set the tab-order, assigned as the Exit macro for every formfield, as follows:

Sub ChangeTabOrder() 
Dim sCurrentFormField As String,
Dim sFormFieldGoTo As String

'First get the name of the current formfield
If (Selection.FormFields.Count = 1) Then
'No textbox but a check- or listbox
    sCurrentFormField = Selection.FormFields(1).Name

ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0 Then
'Textbox
    sCurrentFormField = Selection.Bookmarks(Selection.Bookmarks.Count).Name
End If

'Then find out which formfield to go to next ...
Select Case StrCurFFld
     Case "Better1" : sFormFieldGoTo = "Better3"
     Case "Better2" : sFormFieldGoTo = "Better1"
     Case "Better3" : sFormFieldGoTo = "Better2"
 End Select

ActiveDocument.Bookmarks(sFormFieldGoTo).Range.Fields(1).Result.Select
End Sub


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext