How to find the name of the current formfield

Article contributed by Astrid Zeelenberg

If you need to know which formfield the user tabbed out of in a macro you're using as on-exit macro you need to take into account that you can't always simply use the command Selection.Formfields(1).Name. This line won't work with a textformfield although it works with checkboxes and dropdowns.

If you need code to find out which formfield was tabbed out of, that works with every type of formfield, use:

If Selection.FormFields.Count = 1 Then
    'No textbox but a check- or listbox
    MsgBox Selection.FormFields(1).Name
ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0 Then
    MsgBox Selection.Bookmarks(Selection.Bookmarks.Count).Name
End If