How can I use a macro to navigate activex controls in word 2013?

Please only answer with respect to how this can be done in Word, as that is where the template must be used.

I have created a template form in Word. It uses ActiveX controls. Each of the controls, for simplicity sake in this discussion, have been named tab1 through tab29. I am well aware that this may not be the best naming practice... but again... just for simplicity sake, let's keep it at that: tab1 through tab29.

I chose to use ActiveX controls, because the new standard controls do not allow me to set a maximum number of characters. Something that is a necessity, as I can't have the form morphing out of control when the end user types too much info. The form must fit on one page no matter how much info the end user tries to provide.

I need the end user to be able to press the tab key to move from tab1 to tab2 to tab3 and so on. I had no problem doing this in versions of Office prior to 2007 (I think...) but now... I can't seem to get it working. The only thing I haven't tried so far, is locking the form down - protecting it - because I am not sure I am done developing it. (If someone tells me that doing so is all I need to get the tabs working... /facepalm. I really should try it... but I will wait to see what everyone says. LoL.)

I tried some things that I found online... to no avail. Even the below, which I had nested in the "document" sub of the VB code for the form.

Sub TabOrder()

Dim StrCurFFld As String, StrFFldToGoTo As String

'First get the name of the current formfield
If Selection.FormFields.Count = 1 Then
    'No textbox but a check- or listbox
    StrCurFFld = Selection.FormFields(1).Name
ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0 Then
    'Textbox
    StrCurFFld = Selection.Bookmarks(Selection.Bookmarks.Count).Name
End If

'Then find out which formfield to go to next ...
Select Case StrCurFFld
     Case "tab1"
        StrFFldToGoTo = "tab2"
     Case "tab2"
        StrFFldToGoTo = "tab3"
     Case "tab3"
        StrFFldToGoTo = "tab4"
     Case "tab4"
        StrFFldToGoTo = "tab5"
     Case "tab5"
        StrFFldToGoTo = "tab6"
     Case "tab6"
        StrFFldToGoTo = "tab7"
     Case "tab7"
        StrFFldToGoTo = "tab8"
     Case "tab8"
        StrFFldToGoTo = "tab9"
     Case "tab9"
        StrFFldToGoTo = "tab10"
     Case "tab10"
        StrFFldToGoTo = "tab11"
     Case "tab11"
        StrFFldToGoTo = "tab12"
     Case "tab12"
        StrFFldToGoTo = "tab13"
     Case "tab13"
        StrFFldToGoTo = "tab14"
     Case "tab14"
        StrFFldToGoTo = "tab15"
     Case "tab15"
        StrFFldToGoTo = "tab16"
     Case "tab16"
        StrFFldToGoTo = "tab17"
     Case "tab17"
        StrFFldToGoTo = "tab18"
     Case "tab18"
        StrFFldToGoTo = "tab19"
     Case "tab19"
        StrFFldToGoTo = "tab20"
     Case "tab20"
        StrFFldToGoTo = "tab21"
     Case "tab21"
        StrFFldToGoTo = "tab22"
     Case "tab22"
        StrFFldToGoTo = "tab23"
     Case "tab23"
        StrFFldToGoTo = "tab24"
     Case "tab24"
        StrFFldToGoTo = "tab25"
     Case "tab25"
        StrFFldToGoTo = "tab26"
     Case "tab26"
        StrFFldToGoTo = "tab27"
     Case "tab27"
        StrFFldToGoTo = "tab28"
     Case "tab28"
        StrFFldToGoTo = "tab29"
     Case "tab29"
        StrFFldToGoTo = "tab1"
 End Select
'... and go to it.
ActiveDocument.Bookmarks(StrFFldToGoTo).Range.Fields(1).Result.Select

After a bit, I realized that the code had been generated for an earlier version of word, and probably wouldn't work no matter where it was placed... I just don't know enough about coding for word... Or coding in general, and might have to resort to using another product with which I had no problem making the form work the way I wanted... I just really don't want to admit my shortcomings. I want this form to work!

Can anyone help me get the navigation working?

Answer
Answer

By default,  legacy Text Input formfield is populated with 5 non-breaking spaces

The only way that you can re-size it is by inserting more spaces or some text into it.  That however is not necessary as it will expand to accommodate the text that the user enters into it.

The best way to control the layout of a form is to put, what ever controls that you decide to use inside the cells of a table that has fixed cell dimensions.

Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com
It's time to replace ‘Diversity, Equity & Inclusion’ with ‘Excellence, Opportunity & Civility’ - V Ramaswamy

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 18, 2021 Views 169 Applies to: