Results 1 to 13 of 13
  1. #1
    New Lounger
    Join Date
    Jun 2008
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    UserForm - Update Fields (Word 2003)

    <P ID="edit" class=small>(Edited by jscher2000 on 05-Jan-09 21:14. Added and around the URL to make it a clickable link.)</P>I desperately need help with creating a document where data is entered and then the data appear multiple places within the document eg Firstname, LastName, Title etc. I have followed the instructions from http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm and the form works with the data that is first entered but it does not repeat the required data multiple times where I have used the cross-reference eg {REF firstname h } until I go to Print Preview. Can I have this data appear in my form automatically?

  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

    Re: UserForm - Update Fields (Word 2003)

    You can add a global field update as the last step in your code, after you have filled in the data to the various bookmarks. Try this:

    <code>ActiveDocument.Fields.Update</code>

    If your document contains a table of contents, the user will get a prompt about updating it, which might be disconcerting. Otherwise, it should happen quietly in the background.

    Any luck?

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: UserForm - Update Fields (Word 2003)

    Hi bhapi61,

    Have you made sure the 'calculate on exit' option for each of the formfield properties has been checked?
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    New Lounger
    Join Date
    Jun 2008
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UserForm - Update Fields (Word 2003)

    Hi Paul
    I did originally use FormFields but it wasn’t working cause it would insert data in the cross-reference but not in the bookmarks. So what I did was inserted bookmarks and then inserted cross-reference and it updates the data but only after to I have gone to Print Preview. I don’t want that, I want people to see the data for the bookmarks and cross-reference automatically. Can you tell me what I am doing wrong?
    Thanks heaps.

  5. #5
    New Lounger
    Join Date
    Jun 2008
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UserForm - Update Fields (Word 2003)

    <P ID="edit" class=small>(Edited by jscher2000 on 06-Jan-09 18:03. Added [pre] and [/pre] tags around code to improve readability.)</P>Not sure that I am doing it right. Where should this code be? I have put it at the end of my "UpdateAllField" code, it still doesn't work the way I want it to. It still updates it when you go to Print Preview. That isn't what I want it to do. I want it to update automatically after all the fields have been updated. Also, can you tell me if this code is right maybe my code is wrong (UpdateAllFields)? This is the code I was using:-
    <pre>Sub UpdateAllFields()
    Dim aStory As Range
    Dim aField As Field
    For Each aStory In ActiveDocument.StoryRanges
    For Each aField In aStory.Fields
    aField.Update
    Next aField
    Next aStory
    ActiveDocument.PrintPreview
    ActiveDocument.ClosePrintPreview
    End Sub</pre>


    I then took out the last two lines (ActiveDocument.PrintPreview, ActiveDocument.ClosePrintPreview) and replaced it with ActiveDocument.Fields.Update

    Can you please tell me what I am doing wrong. I am not too good with code.
    Thanks heaps.

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: UserForm - Update Fields (Word 2003)

    Your UpdateAllFields procedure should update all the fields even with my suggested line of code. When are you running it? If you add a Stop as the first line of the procedure and inspect the document, can you confirm that (1) your insertions are in there, and (2) the bookmarks around the inserted data are still valid?

  7. #7
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: UserForm - Update Fields (Word 2003)

    Hi bhapi61,

    Formfields can have their own bookmarks and, as already mentioned, can be set to 'calculate on exit. If you use formfields (eg for the first instance of each item you want to insert), then cross-referencing them doen't require further bookmarks - you simply insert a cross-reference to the formfield's own bookmark. That bookmark can be the one Word allocates (eg 'Text1', 'Text2' etc is the default for text formfields) or one you assign and the cross-references can be formatted in a different font, if you prefer. See attached demo doc.
    Attached Files Attached Files
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  8. #8
    New Lounger
    Join Date
    Jun 2008
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UserForm - Update Fields (Word 2003)

    I understand from looking at your sample how it works, I did at one stage use the Text Form Field, but the problem is that I don’t want (can’t have) the form protected. What I have is a UserForm (followed instructions from http://word.mvps.org/FAQs/Userforms/...AUserForm.htm) that comes up when the file is opened, the required data is entered in the UserFrom and then some data to be repeated in multiple locations within the document. Maybe I shouldn’t be using a UserForm? Any suggestions or what else can I try. I have been on this for a while and it is really driving me crazy as every time I try some new something else goes wrong. Appreciate any help I can get. Thanks heaps.

  9. #9
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: UserForm - Update Fields (Word 2003)

    Hi bhapi61,

    I don't have a problem with the UserForm approach, but what is the objection to protecting the document? If you need to retain some portions as editable, it's a simple matter to use Section breaks around those portions and leave them unprotected.

    With the Userform approach, when you update a value on it, the code attached to the relevant field on your Userform needs to call a macro to update the corresponding bookmark and cross-references. You could use something like:

    Sub UpdateBookmark (BmkNm as string, NewTxt as string)
    Dim BmkRng as Range
    With ActiveDocument
    If .Bookmarks.Exists(BmkNm) Then
    Set BmkRng = .Bookmarks(BmkNm).Range
    BmkRng.Text = NewTxt
    .Bookmarks.Add BmkNm, BmkRng
    Call RefreshFields
    End If
    End With
    Set BmkRng = Nothing
    End sub

    Sub RefreshFields()
    Dim TOC As TableOfContents ‘ Table of Contents Object
    Dim TOA As TableOfAuthorities ‘ Table of Authorities Object
    Dim TOF As TableOfFigures ‘ Table of Figures Object
    Dim pRange As Word.Range ‘ Word Range Object
    Application.ScreenUpdating = False
    With ActiveDocument
    ‘ Loop through Story Ranges and update.
    ‘ Note that this may trigger interactive fields (eg ASK and FILLIN).
    For Each pRange In .StoryRanges
    Do
    pRange.Fields.Update
    Set pRange = pRange.NextStoryRange
    Loop Until pRange Is Nothing
    Next
    ’ The following routines are necessary because the foregoing updates only page numbers
    ’ in TOCs, TOAs and TOFs - field updating doesn’t update TOC, TOA or TOF contents.
    ‘ Loop through Tables Of Contents and update
    For Each TOC In .TablesOfContents
    TOC.Update
    Next
    ‘ Loop through Tables Of Authorities and update
    For Each TOA In .TablesOfAuthorities
    TOA.Update
    Next
    ‘ Loop through Tables Of Figures and update
    For Each TOF In .TablesOfFigures
    TOF.Update
    Next
    End With
    Application.ScreenUpdating = True
    End Sub

    The first macro is already coded to call the second, so there's no need for any additional coding on that score. The second macro may do more than you presently need, but it ensures cross-references in shapes, headers, footers, etc get updated, as well as anything related to the TOC etc.

    For any field on your Userform that needs to update the document, you'd call the first macro with code like:
    Private Sub TextBox1_Change()
    Call UpdateBookmark("BkMrk", TextBox1.Value)
    End Sub
    where "BkMrk" is the name of the bookmark in the document to be updated.

    Note: you only need one bookmark for each Userform field - the rest of the entries are updated vi cross-references fields pointing to that bookmark.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  10. #10
    New Lounger
    Join Date
    Jun 2008
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UserForm - Update Fields (Word 2003)

    thank you so much for all your trouble. I really didn't want to protect the form as there are various people using this form and not everyone understand about sections, protection etc and some are really basic users and I am sure they would scream if they tried to do something and they couldn't. I have tried something else that I use to use way back in Word 97-2000, that is I have created prompts by using fillin fields and bookmarks SET and REF fields.
    - I used {set name {fillin " enter first name here" } {ref name}
    - {ref name} where I want the name to appear multiple times and then saved the document as a template.
    This seams to work fine, do you see any problems with using this method?
    Thanking you again for your help.

  11. #11
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: UserForm - Update Fields (Word 2003)

    Hi bhapi61,

    Using SET, FILLIN and REF fields instead of a Userform or a document protected for forms seems to me to be a solution that's only suitable for those who really know what they're doing. The problems I see with this approach include:
    1. Users are liable to simply overtype the 1st REF field they come to without activating the FILLIN field
    2. Users are liable to be prompted to fill-in the FILLIN fields at print-time, after they've already filled them in (or overtyped one or more REF fields)
    3. The REF fields pointing to a bookmarked FILLIN field don't automatically update - you need to use Ctrl-A & F9, do a Print Preview or print the document

    Also, FWIW, using a STE/FILLIN field combo like {set name {fillin " enter first name here" }} is functionally the same as using an ASK field coded as {ASK name " enter first name here" }

    Using a document protected for forms prevents the user typing or otherwise editing the document anywhere other than where you want them to.

    A Userform gives the user a form into which they can do their initial entry, whilst also giving them full access to the document (if you wish). The risk of allowing full access is that someone's going to dismiss the Userform and edit the document in a way that deletes one or more of the bookmarks that the cross-references need - and any bookmarks that survive an in-document edit won't update throughout the document until you use Ctrl-A & F9, do a Print Preview or print the document..
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  12. #12
    New Lounger
    Join Date
    Jun 2008
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UserForm - Update Fields (Word 2003)

    Addressing your points:-
    1. Users are liable to simply overtype the 1st REF field they come to without activating the FILLIN field –-- I will save the file as a template and this will bring up the fillin-in prompts before going into the document, this will enable all fill-in fields to be competed first.
    2. Users are liable to be prompted to fill-in the FILLIN fields at print-time, after they've already filled them in (or overtyped one or more REF fields) –-- I printed the document before saving and didn’t get the prompt and I also saved the document first and then printed and still didn’t get the prompt, do you know why?
    3. The REF fields pointing to a bookmarked FILLIN field don't automatically update - you need to use Ctrl-A & F9, do a Print Preview or print the document –-- When I opened the template I filled in the initial prompts and the REF fields were updated automatically (without using Ctrl-A or F9), it then took me into the document which allowed me to edit the document. This seems to work exactly the way I want it.

    Also, FWIW, using a SET/FILLIN field combo like {set name {fillin " enter first name here" }} is functionally the same as using an ASK field coded as {ASK name " enter first name here" } --- thanks, I am aware of that.

    Using a document protected for forms prevents the user typing or otherwise editing the document anywhere other than where you want them to. --- I am aware of this but because of the nature of this document sometimes it may be required that paragraphs are removed or added.
    Any comments is appreciatecd. Thank you heaps for all your help once again. You have assured me of what I am trying to do and I have learnt a lot from this project.

  13. #13
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: UserForm - Update Fields (Word 2003)

    Hi bhapi61,

    1. Yes, but that doesn't stop users ignoring a prompt or overtyping a field's contents afterwards.
    2. Users will get this prompt if their Word installation is set to 'update fields' under Tools|Options|Print. There's nothing you can do to control this (ie it's a system-level setting, not a document-specific setting).
    3. Yes, but the cross-references don't update when the FILLIN fields are completed. They will update at print time, though, if Word installation is set to 'update fields' under Tools|Options|Print (see 2, above). Surely you don't want to have to close & re-open the document just to get the cross-references to update!

    If a part of a document protected for forms is liable to need editing, the solution is simple - put Section breaks around that part and leave it unprotected. With this approach, you can even have an cross-reference to a formfield in the editable Section.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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