• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 55
  • Last Modified:

How to auto update specific form fields of word document, while leaving others untouched

I have a macro that lets me update all form fields of my word doc on closing. However, I need it to only update specific form fields, not all. How would I be able to do that?
0
mvp1985
Asked:
mvp1985
  • 3
  • 2
1 Solution
 
GrahamSkanRetiredCommented:
The question is  a little puzzling. Updating is relevant to fields where some computation is necessary to display text according to data exterior to the field. This could, for instance, apply to a REF field or a DATE field.
Form fields do not reference other data. Therefore a FormField object doesn't have an Update method. You can use the more general Field object Update method, but it won't have any effect.
Here is some code, but I wouldn't expect the update to do anything
Sub UpdateFormFields()
    Dim ffld As FormField
    Dim fld As Field
    Dim strFieldNames As String
    Dim strAryFieldNames() As String
    Dim f As Integer
    
    strFieldNames = "Text1,Text3,Text4"
    strAryFieldNames = Split(strFieldNames, ",")
    For f = 0 To UBound(strAryFieldNames)
        Set ffld = ActiveDocument.FormFields(strAryFieldNames(f))
        Set fld = ffld.Range.Fields(1)
        fld.Update
    Next f
End Sub

Open in new window

0
 
mvp1985Author Commented:
Ok, I mistakenly said form fields, when I meant REF field. This means I seem to have the following problem: When I update all REF fields, in my document at once using the keyboard shortcut, my filled out form fields loose all their content.  How can I update the REF fields then without loosing the content from the form fields?
0
 
GrahamSkanRetiredCommented:
Form fields can easily will lose their data if  protection is removed, so that should be avoided after form design is complete.

Field updating will happen whenever a form field that has 'Calculate on exit' set loses focus while the document is protected, so try setting that for some or all of the form fields.
0
 
mvp1985Author Commented:
I have worked around this problem totally by not removing protection anymore, and reworking the entire process.
0
 
mvp1985Author Commented:
I have worked around this problem totally by not removing protection anymore, and reworking the entire process.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now