OCX type fields in a Word Form

P

Peter

Hello,

I have a Word Form that contains regular form field type fields and OCX type
fields. I believe the latter are also known as Active-X fields? These fields
are either checkboxes or optionboxes (radio buttons). I am using them because
they are more flexible. Anyway, for some unknown reason, the macros
associated with these fields stop working. When I investigated why the this
was happening, it turns out that the field names have all been changed so
that they have a "1" appended to the name. If I manually go through and
remove the "1" from each field name, then the code works.
Anyone have any ideas why this is happening?
Also, I've tried to write code that will check the field names on openning
the document but, I can't seem to figure out how to do this. The only classes
I can seem to find to work with here are Fields and FormFields. The OCX type
fields are not part of the FormFields collection and although I can access
them from the Fields collection, the Fields class does not surface the "Name"
property.
Anyone know how to loop through the OCX type fields in a document?

Thanks,
Peter
 
J

Jay Freedman

Here's some sample code that will tell you what you want to know:

Dim oFld As Field
Dim msg As String

For Each oFld In ActiveDocument.Fields
If oFld.Type = wdFieldOCX Then
With oFld.OLEFormat
msg = "Name = " & .Object.Name
If .ClassType = "Forms.CheckBox.1" Or _
.ClassType = "Forms.OptionButton.1" Then
msg = msg & vbCr & _
"Caption = " & .Object.Caption
End If
End With
MsgBox msg
End If
Next

All OCXs have a .Name property, but only some of those have a .Caption
property (and others, as listed in the Properties dialog of the control).
You need to test the .ClassType of the OLEFormat to avoid trying to access a
property that doesn't exist, which would throw an error.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
P

Peter

This is great! Thank you so much.
Do you have any idea why a "1" is getting appended to the field name though?
You know the old saying: "An ounce of prevention is worth a pound of cure".
If I can prevent it from happening then I wont need code to fix it.

Peter
 
P

Peter

Thanks again. I agree wholeheartedly with what you say but unfortunately,
this is one application where a userform just won't work.
Have you tried the new InfoPath 2007 product? This looks from the
advertising that it could replace Word Forms.
 

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