Reference Word Field by Name

J

Jon.NET

Hi there,

Can I refer to a Field by string (Name) to gain access to the Update() and
Select() methods?

To use the Fields Collection you have to pass in an integer (Index):

_objDocument.Fields[index].Select();

The get_Item enumerator does not have the Update() and Select() methods:

_objDocument.Variables.get_Item(ref oVariableName).Value

Thank you

Jon

Jon
 
C

Cindy M.

Hi Jon,
Can I refer to a Field by string (Name) to gain access to the Update() and
Select() methods?
No, at least, not the way you mean it. Consider that a certain field type
might be used in a document more than once - the field name cannot be an
index value as it cannot be unique.

Document Variables are in no way equivalent or comparable to Field objects. A
DocVar is stored in the document's binary file structure. The content can be
displayed in a fields, and could be displayed multiple times in the document
through individual fields having the same syntax.

The closest you could get to what you envision would be to apply a *bookmark*
to the field range, then address the bookmark. Something like (typed by
memory, so there may be syntax errors):
_objDocument.Bookmarks.get_Item("IndexValueName").Range.Fields[1].Select
();

Note that, in this approach, the index value would always be 1 as there is
but the one field in the Range.
To use the Fields Collection you have to pass in an integer (Index):

_objDocument.Fields[index].Select();

The get_Item enumerator does not have the Update() and Select() methods:

_objDocument.Variables.get_Item(ref oVariableName).Value

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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 :)
 
J

Jon.NET

Brilliant - Thanks Cindy.

Jon

Cindy M. said:
Hi Jon,
Can I refer to a Field by string (Name) to gain access to the Update() and
Select() methods?
No, at least, not the way you mean it. Consider that a certain field type
might be used in a document more than once - the field name cannot be an
index value as it cannot be unique.

Document Variables are in no way equivalent or comparable to Field objects. A
DocVar is stored in the document's binary file structure. The content can be
displayed in a fields, and could be displayed multiple times in the document
through individual fields having the same syntax.

The closest you could get to what you envision would be to apply a *bookmark*
to the field range, then address the bookmark. Something like (typed by
memory, so there may be syntax errors):
_objDocument.Bookmarks.get_Item("IndexValueName").Range.Fields[1].Select
();

Note that, in this approach, the index value would always be 1 as there is
but the one field in the Range.
To use the Fields Collection you have to pass in an integer (Index):

_objDocument.Fields[index].Select();

The get_Item enumerator does not have the Update() and Select() methods:

_objDocument.Variables.get_Item(ref oVariableName).Value

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)


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