Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying Word 2003 Form Field Contents? 1

Status
Not open for further replies.

MrKABC

Technical User
Jul 20, 2001
54
US
I'm trying to copy the contents of one Word 2003 form field (NOT a VBA text box) to another on exit of the form field.

I found a wonderful code written by "Fumei" back in June '04 that ALMOST works:
Code:
Sub PassToAppraisee2()
    ActiveDocument.FormFields("APPRAISEE2").Result = _
    ActiveDocument.FormFields("APPRAISEE").Result
End Sub

When place this code in a macro and trigger the macro on exit of the form field, I get an error message "User-Defined type not defined" and the macro terminates.

However, if I run the code from the VBA editor the code works fine. (puzzled?)

The form field is set as "regular text" with "fill-in enabled" and "calculate on exit" enabled.

Is there a setting that I am missing? Should I rewrite this with a variable text string?

Any help would be appreciated, thanks.
 
Hmmmm. I just tested this with two vanilla formfields
Code:
Sub CopyFF()
ActiveDocument.FormFields("Text2").Result = _
        ActiveDocument.FormFields("Text1").Result
End Sub
and it works fine from the document. Not just the VBE.

Hmmmm.

Gerry
 
I wiped out the text form fields, and the macro module, and made a new one.

It works now. Something must have been corrupt? Don't know, but I am happy now!

Thank you Gerry for taking the time to revisit your code (and thanks for your code!) to help me out.
 
Hi MrKABC,

If all you're trying to achieve is to have the results of a text or dropdown formfield replicated elsewhere in the document (the code you're working with implies a text formfield), you don't need a macro or, for that matter, another formfield.

All you need is a REF field that points to the formfield's bookmark and for the formfield to be set to 'calculate on exit'.

Cheers

[MS MVP - Word]
 
Absolutely. Heck , don't even need a REF field. Just do a Ctrl-F9 and type "APPRAISEE". That will take the result of the formfield "APPRAISEE" and duplicate it into that field.

However, the original question was to pass a formfield result to another formfield. Not just duplicate the result.

Gerry
 
Hi Gerry,

In doing that you are, in fact, creating a REF field. The absence of the REF prefix is accepted by Word.

As for what the original question was about that, I know that full well. That's why my response was worded the way it was.

The situations in which you'd need the result to appear in another formfield are few and far between. For example, you might want the source formfield to set a 'default' value for the target formfield, but the intention is to allow the target to be changed. I'd question, though, whether this would be appropriate if the other formfield had already bee filled in, but who knows...

Cheers

[MS MVP - Word]
 
Yes, of course, you are right. And thanks, I learned something. I knew there was no REF prefix, but I should have realized that it, in essense, IS a REF field. Doh.

And you are, of course, correct that having another text formfield filled by a previous one is (most likely) not the best design.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top