Error occur in accessing Word.Field.Data property.

S

Sandeep Sharma

Hi,

I have a custom property name "test" whose value
is "great" in one of my word document which is in word
2000.
I am opening the word document thru a c# application and
then added that field into the document using following
code.

Word.Selection sln = aDoc.ActiveWindow.Selection;
(aDoc.Paragraphs.Count).Range;
object fieldType = Word.WdFieldType.wdFieldEmpty;
object text = "DOCPROPERTY \"test\" ";
object objTrue = true;
Word.Field fld;
fld = sln.Fields.Add(sln.Range, ref fieldType, ref text,
ref objTrue);

MessageBox.Show("Field data " + fld.Data); //runtime error.

I want to access the value (data) of this field "test" and
used Field.Data property which gives a runtime error.

Pls advise what I am doing wrong. How can i access data of
a property.

Thanks.
 
C

Cindy M -WordMVP-

Hi Sandeep,
MessageBox.Show("Field data " + fld.Data); //runtime error.

I want to access the value (data) of this field "test" and
used Field.Data property which gives a runtime error.
the Field object in Word has no DATA property, unless the
feild is an ADDIN field (read up on the property in Word's
Help!)

Try the RESULT property, instead.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep
30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

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