?
Solved

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

Posted on 2014-11-27
5
Medium Priority
?
48 Views
Last Modified: 2015-04-20
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
Comment
Question by:mvp1985
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40468731
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
 

Author Comment

by:mvp1985
ID: 40468761
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40468818
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
 

Accepted Solution

by:
mvp1985 earned 0 total points
ID: 40724730
I have worked around this problem totally by not removing protection anymore, and reworking the entire process.
0
 

Author Closing Comment

by:mvp1985
ID: 40733034
I have worked around this problem totally by not removing protection anymore, and reworking the entire process.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
Suggested Courses
Course of the Month11 days, 5 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question