fields not displaying update in all locations

C

cayce

A field update is not displaying the change after the macro is run. The user
can go to the individual field and right-click, choose update, and thereby
force it to display the update. However, in a long document, this can be
tedious. In this case, it is a field appearing in a footer that does not
update. Curiously, the title (first) page of the document has a text box with
this same field and it DOES display the update there.

I am not the person who created these macros and do not know VBA. We are now
using W2007, but the macros were created in W2003.

Does anyone have any ideas?

Finally, is there some sort of global command to force all fields in a
document to update and display same?
 
G

Gordon Bentley-Mix

Cayce,

This is a common problem that's been discussed several times in this forum.
Basically the problem is that headers, footers, textboxes, etc. are in a
different part of the document from the main body. Even if a macro contains
some code to update fields, such as "ActiveDocument.Fields.Update", the
fields in these different parts aren't updated; only those in the body are.

There are several solutions to this problem:
1) You can simply print preview the document, which can be done
programmatically without too much fuss. However, this only works if the
option to update fields on print is set. (This can also be set
programmatically but I'd recommended taking steps to reset it back to its
previous state so the users don't get any surprises; you don't want to change
things without the users knowing it.)

2) You can write code to cycle through all the different parts of the
document and update the fields in each part. This takes a bit more work, but
I prefer it over the 'print preview' method because it is done for a specific
purpose. The 'print preview' method relies on re-purposing functionality and
what I'd call a "side effect" to achieve the result - kind of like taking a
low dose of a tricyclic antidepressant to help you sleep; not really what it
was intended for but it gets the job done.

Unfortunately, I can't remember the specific code for implementing the first
method (since I never use it) but I'm sure someone else would be happy to
help in that regard. However, if you're interested in the second method, the
following code will help you get started:

Private Sub UpdateAllFields()
Dim mySection As Section
Dim myHeader As HeaderFooter
Dim myFooter As HeaderFooter
Dim myTextBox As Shape
For Each mySection In ActiveDocument.Sections
For Each myHeader In mySection.Headers
myHeader.Range.Fields.Update
Next myHeader
For Each myFooter In mySection.Footers
myFooter.Range.Fields.Update
Next myFooter
Next mySection
For Each myTextBox In ActiveDocument.Shapes
If myTextBox.Type = msoTextBox Then
myTextBox.TextFrame.TextRange.Fields.Update
End If
Next myTextBox
End Sub

If you need any clarification on the above, let me know.
--
Cheers!
Gordon
The Kiwi Koder

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
C

cayce

Gordon...thanks for such a thorough response!

I am familiar with the different "layers" Word uses for partitioning off
content. What was really throwing me off though is this document has the SAME
page layout as several others (eg. there is a title page with text boxes that
precede the TOC and content pages). This is the only file in the bunch
misbehaving this way.

Am I to gather that there is no global command to tell users to use to force
the fields to update? If not, I can easily tell them what to define in Word's
options to force updates when they choose print preview.

By the way, I enjoyed your antidepressant analogy. Kind of like using a
wrench to accomplish what really calls for a hammer. Finally from your sign
off, it might be fun to know that Burt Munro is one of my heroes.

Namaste
 
G

Gordon Bentley-Mix

G'day Cayce,

Strange that only this doc is playing up. I'd be interested in having a look
at it and at one that does work for comparison. The email address in my
profile is valid if you're so inclined...

As for a "global field update" command, I've never found one. The only
workaround I'm aware of is the knock-on from the print preview. If you don't
want or need a programmatic solution then it's as simple as checking the
"Update fields" option on the Print tab of the Options dialog and then
instructing the users to print preview the doc after it's been created. (Note
that this applies to Word 2003, but the option is available in other versions
- I just can't recall off the top of my head if it's exactly the same.) I
believe that this is an application-level option, rather than a
document-specific one, so once set it should apply to all docs.

--
Kia kaha!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top