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!

Word: Fields vs FormFields

Status
Not open for further replies.

JohnnieMiami

Programmer
Feb 4, 2006
5
US
Hello!
I am trying to process a Word document that someone has provided to me. Its seems like the easiest thing to do would be to access the form fields like doc.activedocument.formfields("MyField1").value but that throws an error. I checked formfields.count and get 0. However, if I check doc.activedocument.fields.count I get the 117 (the number I would expect). However, when I try to access the field values using something like:
oword.ActiveDocument.Fields(1).Result.Text.ToString

I get:
"Error! Not a valid embedded object."

I'm using vb.net to access the values in the controls. Can you tell me what the difference is between a "field" and a "formfield" and how I can access the value in the "fields" object.

Thank you!
-Miami
 
1. Do you see any formfields in the document?
2. When you go Alt-F9 do you see field codes?

BTW: other than dropdowns, to get real values out of formfields you nornamlly use Formfields("Blahblah").Result.

Formfields are essentially special user editable bookmarks - which is why they also appear in the Bookmarks collection.

Fields are Range objects - well, not really, bit sort of..they are their own object - defined by their field codes.

I am not sure why you are getting that error.
Code:
Dim oField As Word.Field
For Each oField In ActiveDocument.Fields()
    MsgBox oField.Result
Next
displays all field results (in text) for me.

So...can you see the field codes????

Gerry
 
Thanks fumei. When I press Alt-F9 I see things like:

{ CONTROL Forms.OptionButton.1 \s}
{ HTMLCONTROL Forms.HTML:Text.1 \s} - this appears many times

Are these form fields?

I also inserted your code and it gave me an error saying that oField.Result is not of a string type. I then tried to print oField.Result.Text.ToString and got:

"Error! Not a valid embedded object."

Any ideas?

Thanks!
Bob
 
Hi Bob,

No they're not Word FormFields - they're ActiveX objects - copied from a web page, I would think. This box you type the post in here is like your second example.

It depends on the types but try looking at ..

Code:
[i]FieldRef[/i].OLEFormat.Object.Value

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Thanks Tony! That seems to be it. Is there a reason to use Active X over FormFields?

Thanks!
Bob
 
Hi Bob,

ActiveX potentially provides far more capability than Word Forms, but if what you want is a straightforward fill-in form then FormFields are designed to work within Word and would normally be the solution of choice - they have their problems, of course, but doesn't everything?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony is correct of course. These are not formfields, nor are they fields. They are ActiveX objects.

I have to ask...what are you trying to do? Are you trying to have this as a workable document?

Gerry
 
I've been given a bunch of Word documents that have a form in them with a bunch of questions. They want me to extract the information from these docs and put in a database. With Tony's help I've been able to get most of the data. It seems as if they are using an HTMLOption that returns the radio button value (e.g. "Yes", "No") whether its selected or not. I'm guessing I would need to use a Checked value but it doesn't seem to like that (doc.Fields(115).OLEFormat.Object.checked).

Thanks again guys!
Bob
 
Whoops....doc.fields(115).OLEFormat.Object.checked worked...I was using doc.fields(115).OLEFormat.Object.check and that failed.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top