Automatic Field Update

  • Thread starter Thread starter Mike Morisoli
  • Start date Start date
M

Mike Morisoli

We have numerous Word documents stored in Sharepoint and we would like to
show the latest field data every time a document is opened.



Does anyone have a suggestion on the best way to do this? Is it a matter of
adding a macro that fires every time the document is opened and it then
selects the entire document and issues the F9 update via code, or is there a
simpler solution.



Thanks for the ideas,



Mike
 
That _is_ the simple solution. However, you probably do not want ASK or
FILLIN fields to update each time a document is opened.

What are you doing with these documents? Would it be done better with
templates? Properly, a document is something you open, make changes, and
save the changes (to the same name). You may do this repeatedly. You may
print it. A template is a base from which new documents are created. Changes
are made to those new documents and then they can be saved and/or printed.
They don't take the name of the template.

Which fields need updating?

--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
Given the provisos raised by Charles - an autoopen macro in the document
template containing:

ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview

would probably suffice.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP

Web site www.gmayor.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
 
So far as I know the PrintPreview method only works for fields in
headers/footers (which the proposed macro selecting and updating won't
reach).

I just tested it using CreateDate and SaveDate fields in the body of a
document. (I switched in and out of Print Preview manually instead of by
code.)


--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
Did you have "Update fields" checked on the Print tab of Tools | Options?

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
AHH....No! I unchecked that ages ago because I didn't like filling out
Fill-In fields and ASK fields again when I printed.

I tested again, with the option checked and preview did update the fields in
my document. Then, in Word 2003, I checked with ASK and Fill-In fields, and
it repeated that annoying behavior as well. (Print Preview did not trigger
that.) I guess I'll leave it unchecked still.

I tried the following macro but it doesn't work. I suspect it resets the
option too quickly.

Sub FieldUpdater()
' Macro to update fields in document other than Ask and Fill-In fields
Dim bUpdate As Boolean
bUpdate = Options.UpdateFieldsAtPrint
Options.UpdateFieldsAtPrint = True
ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview
Options.UpdateFieldsAtPrint = bUpdate
End Sub

The statements suggested by Graham, by themselves, do work if the "update
fields at print" option is properly set.

--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
Yet one more update on updating fields...

I checked again, and even with "Update fields" checked, Print Preview and
the related code flicking in and out does not update a CreateDate field in a
document body, although printing does. (The createdate field normally never
has to be updated in a document. In this one, I created the field in a
document and then used SaveAs to save it to a new name. If I manually update
the field it reflects the creation date for the new docmument. Same if I
print with the option checked. Not so, though, with Print Preview. So I
guess it depends on which fields you want to update. I know it works well,
although not perfectly, with fields in the header/footer.
--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
Yes, printing or Print Preview updates all fields in the header/footer
regardless of the Print Options setting. The only field I specifically know
doesn't update automatically in Word 2003 is the FILENAME field (see “The
FILENAME field does not automatically update when you open a document in
Word 2002 or Word 2003” at http://support.microsoft.com/?kbid=832897).

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
Hi Charles,

Print Preview probably won't update a CreateDate field because saving the
document for the first time is required to set that property...

Cheers
 
I think you must have missed this sentence "I created the field in a
document and then used SaveAs to save it to a new name"

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP

Web site www.gmayor.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
 
When you have such a field in an already saved document and then use the
Save As command to save it, even to the same name, it changes the creation
date for the file. If the field is updated, it will change.
--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
Back
Top