Accessing the content of a FormField when opening a document

R

Ron.snape

Hi

I'm relatively new to vba programming in word, and I've got a bit stuck. I
have a document which consists of a number sections, each of which contains a
number of FormFields. Each Section is completed by a different individual in
a logical progression.

I've created a separate Formfield called 'FControl' which is empty when the
document is initially opened. This is updated with the identifier of the
individual/stage being completed at the end of the stage before it is saved
and closed ready for the next individual to open it and do their thing.

I've modified the Document_Open macro so that it tests the value of
'VControl', but I can't seem to access the value as no matter what the
content of 'FControl', it returns a Null value ("")) even though I can see
that it actually contains a valid value such as "EMP" or "LIN".

I'm checking the value using the code :

If ActiveDocument.Formfields("bkFControl").Result = "EMP" then .....

What am I doing wrong?

Any assistance gratefully received.

Thanks

Ron
 
J

Jean-Guy Marcil

(e-mail address removed) was telling us:
(e-mail address removed) nous racontait que :
Hi

I'm relatively new to vba programming in word, and I've got a bit
stuck. I have a document which consists of a number sections, each
of which contains a number of FormFields. Each Section is completed
by a different individual in a logical progression.

I've created a separate Formfield called 'FControl' which is empty
when the document is initially opened. This is updated with the
identifier of the individual/stage being completed at the end of the
stage before it is saved and closed ready for the next individual to
open it and do their thing.

I've modified the Document_Open macro so that it tests the value of
'VControl', but I can't seem to access the value as no matter what the
content of 'FControl', it returns a Null value ("")) even though I
can see that it actually contains a valid value such as "EMP" or
"LIN".

I'm checking the value using the code :

If ActiveDocument.Formfields("bkFControl").Result = "EMP" then .....

What is the actual name of the field?
In your post you use three names:
'FControl'
'VControl'
"bkFControl"

If it is called "FControl" (I will assume that "VControl" is a typo), why do
you use "bkFControl" in your code?

And what type of field is it?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
R

Ron.snape

Jean

Sorry - you're right - the 'V' was a typo.

The field is a Text Form Field with the bookmark set to 'bkFControl'. When
I couldn't get it to work, I then defined a string variable 'FControl' which
I loaded from the Text Form Field result so that I could then test that
instead, but that didn't work either.

Neither of the following statements work as ("") is returned in both
instances :

1) FControl = ActiveDocument.Formfields("bkFControl").Result
If FControl = "EMP" then .....

2) If ActiveDocument.Formfields("bkFControl").Result = "EMP" then ....

Cheers

Ron
 
J

Jean-Guy Marcil

(e-mail address removed) was telling us:
(e-mail address removed) nous racontait que :
Jean

Sorry - you're right - the 'V' was a typo.

The field is a Text Form Field with the bookmark set to 'bkFControl'.
When I couldn't get it to work, I then defined a string variable
'FControl' which I loaded from the Text Form Field result so that I
could then test that instead, but that didn't work either.

Neither of the following statements work as ("") is returned in both
instances :

1) FControl = ActiveDocument.Formfields("bkFControl").Result
If FControl = "EMP" then .....

2) If ActiveDocument.Formfields("bkFControl").Result = "EMP" then
....

If you double-click on the field, what bookmark name do you see in the
bottom right corner of the property dialog?
2) If ActiveDocument.Formfields("bkFControl").Result = "EMP" then
should return true if, as you say, the formfield contains "EMP".
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
R

Ron.snape

Jean

Sorry I haven't responded earlier - payroll falling down around my ears!

If I double-click on the field, I get a box headed 'Text Form Field options'
and under Field Settings, the Bookmark name is shown as 'bkFControl'.

By trial & error, I think that I've now solved the problem by using the
instruction :

FControl = ActiveDocument.Formfields("bkFControl").Range.Text

which does return the text value held in the FormField, and my code now
seems to run properly.

Thanks for your assistance.

Regards

Ron Snape
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top