Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Form fields with macros seem to prevent refreshing (update) of cross refs

    Hi all,

    I have just written a whole small app based on form fields and that each form field calls a macro when you leave a form after updating it.

    And then I found that form fields with macros seem to prevent refreshing (update) of cross refs. I have checked this many times that this is the "cause" of the problem. I started a fresh document and slowly added more and more components in, and I found that when both the form fields *and* the macros were present, then Word could not perform even the simplest of fields updates. E.g., write some text in the doc, like "hello", create a bookmark around it, then somewhere else insert a cross-ref to the bookmark. So you get "hello". Then go to the source text and change it to "hellllllo". Then pressing F9 should change the text to "hellllllo".

    It does not. Can't refresh the field.

    I have checked that the fields are not locked.

    Any ideas?

    Anyway ... it looks as if I am going to have to completely redesign my solution. Drat! :-(

    TIA

    -avraham

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Which version of Word, which format (DOC or DOCX), and are they legacy form fields from Word 97-2003, ActiveX controls, or the newer Word 2007-2010 ones?

    Could you post a sample document demonstrating the problem?

  3. #3
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hi jscher,

    Thanks for the quick response.

    This is a DOCX file- however the same problem happened also with DOC files.

    And yep - these are legacy form fields from Word 97-2003.
    I like to use what I am familiar with.

    -----------------

    But I just found a solution!

    This was obviously a bug that nobody was ever gonna work out, I decided, so I started to recode the app. I tried Content Controls - but they don't seem to offer macros.

    So then , I decided to include ActiveX controls. I placed an ActiveX text box on the document and then double-clicked the text box to see where it would take me. And lo and behold it opened the VBA dev environment and placed a click handler in the ThisDocument "module".

    So that gave me the idea: I did not put the form field macros in the ThisDocument module. I put them in some other module. This would be outrageous if this was in fact causing the problem, but it was worth a try. So I moved the form field macros into the ThisDocument module. Then I went back to my Word document edited the Hello bookmark to see if I could refresh a reference to the bookmark, and guess what ...

    It worked.

    So I am back with my original form fields and their macros.

    I think an angel must have come from heaven to give me that idea...

    Thanks.

    -avraham


    Quote Originally Posted by jscher2000 View Post
    Which version of Word, which format (DOC or DOCX), and are they legacy form fields from Word 97-2003, ActiveX controls, or the newer Word 2007-2010 ones?

    Could you post a sample document demonstrating the problem?

  4. #4
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts
    So what do you say, jscher? This bug is a candidate for 'the most outrageous bug of the month' award...?

    -avraham
    Last edited by jscher2000; 2011-08-16 at 21:21. Reason: Removed quotation.

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by amakeler View Post
    So what do you say, jscher? This bug is a candidate for 'the most outrageous bug of the month' award...?
    It definitely doesn't make sense for the module to matter in this case. (It matters for event handlers, but shouldn't matter for this.) Perhaps we should wait until the 31st to call the most outrageous.

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Hi avraham,

    It seems to me there's a basic misunderstanding in your first post, about how updating fields, in a document which is protected for forms, should behave. In short, the only practical way to make use of form fields in a document is to protect the document - to permit only editing in the form fields (otherwise, editing the formfields will just delete them).
    But once a document is protected to permit only editing in formfields, Word's native 'update fields' functionality is disabled - this is by design and has always been that way. So if you press F9 while a document is protected for forms, nothing is going to happen. (And this will be the case, whether or not you have macros associated with the form fields.)

    The only way to get fields to update in a document which is protected for forms, is to add code to an OnEntry or OnExit macro, to (1) unprotect the document, (2) update all (or selected) fields, and (3) reprotect the document.

    If you do this, the cross-ref fields should update.

    Gary

  7. #7
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts
    I agree w/ GF but remain puzzled that putting the macros in a different module seems to allow the fields to update (unless those macros are unprotecting and reprotecting the form).
    Charles Kyle Kenyon
    Madison, Wisconsin

  8. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Quote Originally Posted by Gary Frieder View Post
    The only way to get fields to update in a document which is protected for forms, is to add code to an OnEntry or OnExit macro, to (1) unprotect the document, (2) update all (or selected) fields, and (3) reprotect the document.
    You don't need a macro - simply set the 'calculate on exit' property for each formfield. Even though they may have nothing to do with the X-refs, those should be updated too. Alternatively, a print preview should do the job. TOCs are a whole different animal, though, but a workaround I developed means even they can be updated in a protected document (again with no macros).
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. #9
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Paul,

    Thanks for this needed reminder!

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •