UserForm & Bookmark Updates not Working

L

LittleAnn

I have created a Template based on a report document. In the template I have
added bookmarks to the various information the report needs to populate
correctly, i.e Document Title, Document Refence, Date, Status, Date of Issue
etc.

I have REF all the above info throughout the document as the same info
appears in the Main text of the Report and in the Header and Footer.

I then created my userform to appear once a new document was created asking
the user to input the info required.

My problem is that everytime I test it, the Userform works fine but it only
enters the info into the first bookmarked areas, i.e the front cover, and
does not update in the REF fields, I have added a AutoNew macro and an
AutoUpdate Macro but nothing seems to work.

Any ideas what I'm doing wrong??

(P.S. The REF fields work fine if I input a FILLIN field, but this asks for
several prompts to complete the info needed which I did not want to do, thus
why I created the user form)
 
J

Jay Freedman

You haven't done anything wrong, you just haven't done enough.

REF fields never update automatically; something else is needed to force
them to update.

In the code of your userform, or in the macros that call it up, add this
code after the bookmarks have been populated with data:

Dim rngStory As Word.Range

For Each rngStory In ActiveDocument.StoryRanges

'Iterate through all linked stories

Do

rngStory.Fields.Update

'Get next linked story (if any)

Set rngStory = rngStory.NextStoryRange

Loop Until rngStory Is Nothing

Next


--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
M

macropod

Hi LittleAnn,

Here's another approach, which should work for you:

Sub UpdateFields()
Application.ScreenUpdating = False
ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview
Application.ScreenUpdating = True
End Sub

Note: some fields (eg a filename field in the body of the document) are not updated by this, but most are.
 
L

LittleAnn

Thank you for your response.

I have tried both these macros and nothing is happening. The REF fields
still are not updating with the info that is inserted into the Userform.

Any other ideas what might be going wrong??

Thanks

macropod said:
Hi LittleAnn,

Here's another approach, which should work for you:

Sub UpdateFields()
Application.ScreenUpdating = False
ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview
Application.ScreenUpdating = True
End Sub

Note: some fields (eg a filename field in the body of the document) are not updated by this, but most are.

--
Cheers
macropod
[MVP - Microsoft Word]


LittleAnn said:
I have created a Template based on a report document. In the template I have
added bookmarks to the various information the report needs to populate
correctly, i.e Document Title, Document Refence, Date, Status, Date of Issue
etc.

I have REF all the above info throughout the document as the same info
appears in the Main text of the Report and in the Header and Footer.

I then created my userform to appear once a new document was created asking
the user to input the info required.

My problem is that everytime I test it, the Userform works fine but it only
enters the info into the first bookmarked areas, i.e the front cover, and
does not update in the REF fields, I have added a AutoNew macro and an
AutoUpdate Macro but nothing seems to work.

Any ideas what I'm doing wrong??

(P.S. The REF fields work fine if I input a FILLIN field, but this asks for
several prompts to complete the info needed which I did not want to do, thus
why I created the user form)
 
J

Jay Freedman

I have a suspicion...

If your macro/userform inserts the data at the bookmarks in a way that puts the
inserted text before or after the bookmarks but not _inside_ the bookmarks, then
the REF fields are pointing to empty bookmarks. You may need to recode that part
of the userform as shown in
http://www.word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm.

To determine whether this is what's happening, go to Tools > Options > View and
check the box for Bookmarks. Then look at the results after the userform runs.
If the bookmarks appear as thick gray I-beams to the left or right of the
inserted text, this is the problem. When it's done right, they should appear as
thick gray square brackets surrounding the text, like [inserted data] .

One other bit: If you use macropod's technique, you have to have checked the
Update Fields box in Tools > Options > Print. If this is being supplied to other
users, you should code the macro to store the current value of
Options.UpdateFieldsAtPrint and set that option to True before updating, then
set it back to its original value.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.

Thank you for your response.

I have tried both these macros and nothing is happening. The REF fields
still are not updating with the info that is inserted into the Userform.

Any other ideas what might be going wrong??

Thanks

macropod said:
Hi LittleAnn,

Here's another approach, which should work for you:

Sub UpdateFields()
Application.ScreenUpdating = False
ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview
Application.ScreenUpdating = True
End Sub

Note: some fields (eg a filename field in the body of the document) are not updated by this, but most are.

--
Cheers
macropod
[MVP - Microsoft Word]


LittleAnn said:
I have created a Template based on a report document. In the template I have
added bookmarks to the various information the report needs to populate
correctly, i.e Document Title, Document Refence, Date, Status, Date of Issue
etc.

I have REF all the above info throughout the document as the same info
appears in the Main text of the Report and in the Header and Footer.

I then created my userform to appear once a new document was created asking
the user to input the info required.

My problem is that everytime I test it, the Userform works fine but it only
enters the info into the first bookmarked areas, i.e the front cover, and
does not update in the REF fields, I have added a AutoNew macro and an
AutoUpdate Macro but nothing seems to work.

Any ideas what I'm doing wrong??

(P.S. The REF fields work fine if I input a FILLIN field, but this asks for
several prompts to complete the info needed which I did not want to do, thus
why I created the user form)
 

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