Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Jan 2003
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Updating Calculation Fields in Protected Form (Word 2000)

    Could someone please help me with the code to update form fields (calculation fields) before the document is saved and sent to print and before we "unlink" the fields. I have tried with the code below but it doesn't work (the updating fields part only doesn't work--the code without the updating fields works fine for unlinking fields). Any guidance would be much appreciated. Thanks...Mary

    Sub mjaUnprotectFormLockFieldInfo()

    If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect "123456"
    Selection.HomeKey Unit:=wdStory

    Selection.WholeStory
    ' Selection.Fields.Update
    Selection.Fields.Unlink
    Selection.HomeKey Unit:=wdStory

    If ActiveDocument.ProtectionType = wdNoProtection Then

    ActiveDocument.Protect _
    Type:=wdAllowOnlyFormFields, noreset:=True, Password:="123456"

    End If
    End Sub

  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: Updating Calculation Fields in Protected Form

    The line that's commented out (with the ' character) does seem as though it should work. You can try it without the Selection too:

    With ActiveDocument.StoryRanges(wdMainTextStory).Fields
    .Update
    .Unlink
    End With

    If this doesn't work either, could it be that your fields are locked against updating?

  3. #3
    2 Star Lounger
    Join Date
    Jan 2003
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating Calculation Fields in Protected Form

    Many thanks! I first tried putting your code in AFTER the unprotect code, but once again it didn't work. Then I tried putting the code in in place of the original unprotect code and it still didn't work--the ".Unlink" line being the problem. I then deleted the ".Unlink" line and reactivated the original If ...End If code that I had before, and now the following macro works great! Once again, many thanks for your help and quick response!...Mary

    With ActiveDocument.StoryRanges(wdMainTextStory).Fields
    .Update
    End With
    If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect "123456"
    Selection.HomeKey Unit:=wdStory

    Selection.WholeStory
    Selection.Fields.Unlink
    Selection.HomeKey Unit:=wdStory

    If ActiveDocument.ProtectionType = wdNoProtection Then

    ActiveDocument.Protect _
    Type:=wdAllowOnlyFormFields, noreset:=True, Password:="123456"

    End If

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating Calculation Fields in Protected Form

    Hi Mary:
    FYI. When you unprotect a document & then update a form field, it reverts to its default value. That's why you have to update it first, then unprotect & unlink.
    Cheers,

Posting Permissions

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