Control Tab Order in Form

User avatar
arroway
3StarLounger
Posts: 368
Joined: 04 Jan 2012, 22:43

Control Tab Order in Form

Post by arroway »

In a locked Word03 document with named legacy Text Form Fields is there any VBA way of controlling the Tab Order?
--Dax
It takes 2 to tango; unless you speak binary; then it takes 10.

User avatar
HansV
Administrator
Posts: 78402
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Control Tab Order in Form

Post by HansV »

Best wishes,
Hans

User avatar
arroway
3StarLounger
Posts: 368
Joined: 04 Jan 2012, 22:43

Re: Control Tab Order in Form

Post by arroway »

Thanks for your help Hans. One quick thing please. How do I make it so the cursor is at the formfield: bLastname on open? And where should I put the code, in the Module or in the This Document?
Thank you!
--Dax
It takes 2 to tango; unless you speak binary; then it takes 10.

User avatar
HansV
Administrator
Posts: 78402
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Control Tab Order in Form

Post by HansV »

In the ThisDocument module:

Code: Select all

Private Sub Document_Open()
    ActiveDocument.Bookmarks("bLastName").Range.Fields(1).Result.Select
End Sub
(I mistakenly wrote ThisWorkbook originally, but that's for Excel, of course.)
Best wishes,
Hans

User avatar
arroway
3StarLounger
Posts: 368
Joined: 04 Jan 2012, 22:43

Re: Control Tab Order in Form

Post by arroway »

Thanks Hans. I did catch the ThisWorkbook. I also put it in the ThisDocument module but its not working. Not quite sure why. It's a locked Word03 form template that lives on the server--does that help shine any light? And oy veh! The setting the Tab Order thing is driving me nuts! My form has 92 fields so I'm using the second suggestion, which, on my dummy form (7 fields) works just great but on my actual form it works but not as expected. On open, for example, I want it to go to Text32 (or bLastName). From there I want it to go to Text02, then Text01, then to other places in the document. Currently, from Text32 it goes to Text01 (not Text02 like it's written) and then goes to Text02 and keeps going back to the same field (as if it says, "Case "Text02" StrFFldToGoTo = "Text02"). IT's sort of working as it does jump around the page but not the way I'm instructing with my VBA and I'm wondering if you might be able to shed any light on the situation. Do the text fields need to be in the same order as they appear on the sheet or can they be in any order? I've tried rearranging them but they still behave the same. I'm sort of scratching my head on this one (and wondering if it's really worth it. HA!) One other thing is that I'm only instructing 17 of the formfields on the page. I'm doing this because I don't want to write macros for all 92 fields. In my test document I tried it and it worked to do it like this:

The natural progression goes: 1, 2, 3, 4, 5, 6, 7 If I want it to go 5, 2, 3, 4, 1, 6, 7 I don't include VBA for items 3, 4, or 6 as they follow the natural order. I say, "5 goto 2, 4 goto 1, 1 goto 6" and that's it. I'm not sure if doing it this way is causing my problem but in my test doc, it worked just fine.
Thanks for looking.
--Dax
It takes 2 to tango; unless you speak binary; then it takes 10.

User avatar
HansV
Administrator
Posts: 78402
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Control Tab Order in Form

Post by HansV »

As the article on the Word MVP site mentions, "a UserForm (Microsoft-speak for a custom dialog box) is usually a much more elegant solution for form filling than a document-based form. 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."

Form fields are an ancient and clunky feature of Word, and they weren't designed for sophisticated forms. I myself would never even try to set the tab order for 92 form fields... :hairout:

However, both the Document_Open event procedure and TabOrder macro work OK for me.

I hope that you didn't forget to set the TabOrder macro as On Exit macro for the form fields. And made sure that each form field has a unique bookmark name, and that you're referring to the correct names.
Best wishes,
Hans

User avatar
arroway
3StarLounger
Posts: 368
Joined: 04 Jan 2012, 22:43

Re: Control Tab Order in Form

Post by arroway »

Yep, set the macro as On Exit on all the ones that get mentioned (not on all 92), unique bookmark names, double and triple checked. Ancient and clunky for sure! I'll keep messing with it to see if I can get it to work (but not for very much longer!). Thanks for all your help.
--Dax
It takes 2 to tango; unless you speak binary; then it takes 10.

User avatar
HansV
Administrator
Posts: 78402
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Control Tab Order in Form

Post by HansV »

If you wish you can attach a copy of the document, so that others can have a look at it...
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78402
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Control Tab Order in Form

Post by HansV »

For what it's worth, here is a sample document with 8 form fields.
TabOrder.docm
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans