none
Macro isn't executed after leaving text field RRS feed

  • Question

  • Hello

    For a while now we have been using Selection.InsertFile to insert a piece of text from another Word file. This is done using a macro, containing the Selection.InsertFile code, after leaving (tabbing out of) a text field. In this text field the name of a bookmark is provided and it's the textfragment in this bookmark in the "foreign" file that is inserted in a certain region.

    We recently extended the list of possibilities (fragments of text) in the "foreign" Word file with checkboxes (new kind in Word 2010). After selecting a bookmark with these checkboxes in the text field, the text is inserted but if we want to change this text by another bookmark, using the same functionality (with the text field) it no longer works with the tab key. It does however work still by clicking into the text field and than somewhere outside of it.

    After choosing another bookmark in the text field, not containing any checkbox, but plain text, the tab key functions again as to be expected.

    Is there any way to keep using the tab with the checkboxes?

    Friday, March 29, 2013 11:46 AM

Answers

  • Unlike Formfields, Content Controls do not have an 'on exit' property, so tabbing out of them won't trigger an update unless you use either a macro or linked Content Controls.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Saturday, March 30, 2013 1:32 AM
  • The following assumes that your bookmark selection field is a "legacy text input field" and that you are using the "On exit" property to insert the bookmarked text(+checkbox). 

    As far as I can tell, this problem results from using content controls in conjunction with "protection for forms," which is more likely to cause problems with the "tab order" (i.e. the sequence in which forms controls are visited when you tab around the document.

    Without "protection for forms", tabbing visits one plain text control, then the next, until you reach the end. With "protection for forms" switched on, singleton checkboxes are skipped, but if you have two checkboxes with no plain text control between them, tabbing goes to the second checkbox then "sticks".

    If you are using legacy controls, then you have to use "protection for forms", but the above behaviour for content controls is the same. If you tab from a legacy field, the next field reached could be a content control or a legacy field. If it's a content control, tabbing then moves from one content control to the next and ignores the legacy fields. 

    I have to say that when testing, if I inserted bookmarked text containing a single content control checkbox, I did not see problems. But if it contained two checkboxes, the above "rules" came into play and the form got "stuck" on the second one. You might be able to fix that by ensuring that you mark the checkbox as "contents cannot be edited" in the document that you are inserting it from (i.e. using the properties button on the Developer tab). But in that case, I think you will see different problems.

    So I suspect that you will need to change your form so that it only uses content controls and their "On Exit" events, rather than legacy controls. Or you might be able to use a legacy checkbox (in that case you would probably have to take steps to ensure that all your checkboxes had different names). It depends on what you are trying to achieve.


    Peter Jamieson

    Saturday, March 30, 2013 12:59 PM

All replies

  • Unlike Formfields, Content Controls do not have an 'on exit' property, so tabbing out of them won't trigger an update unless you use either a macro or linked Content Controls.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Saturday, March 30, 2013 1:32 AM
  • The following assumes that your bookmark selection field is a "legacy text input field" and that you are using the "On exit" property to insert the bookmarked text(+checkbox). 

    As far as I can tell, this problem results from using content controls in conjunction with "protection for forms," which is more likely to cause problems with the "tab order" (i.e. the sequence in which forms controls are visited when you tab around the document.

    Without "protection for forms", tabbing visits one plain text control, then the next, until you reach the end. With "protection for forms" switched on, singleton checkboxes are skipped, but if you have two checkboxes with no plain text control between them, tabbing goes to the second checkbox then "sticks".

    If you are using legacy controls, then you have to use "protection for forms", but the above behaviour for content controls is the same. If you tab from a legacy field, the next field reached could be a content control or a legacy field. If it's a content control, tabbing then moves from one content control to the next and ignores the legacy fields. 

    I have to say that when testing, if I inserted bookmarked text containing a single content control checkbox, I did not see problems. But if it contained two checkboxes, the above "rules" came into play and the form got "stuck" on the second one. You might be able to fix that by ensuring that you mark the checkbox as "contents cannot be edited" in the document that you are inserting it from (i.e. using the properties button on the Developer tab). But in that case, I think you will see different problems.

    So I suspect that you will need to change your form so that it only uses content controls and their "On Exit" events, rather than legacy controls. Or you might be able to use a legacy checkbox (in that case you would probably have to take steps to ensure that all your checkboxes had different names). It depends on what you are trying to achieve.


    Peter Jamieson

    Saturday, March 30, 2013 12:59 PM