Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2007

Tip: Looking for answers? Try searching our database.

OCX type fields in a Word Form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter - 14 Dec 2007 17:35 GMT
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
Jay Freedman - 14 Dec 2007 18:51 GMT
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.

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> Hello,
>
[quoted text clipped - 18 lines]
> Thanks,
> Peter
Peter - 14 Dec 2007 19:04 GMT
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

> Here's some sample code that will tell you what you want to know:
>
[quoted text clipped - 42 lines]
> > Thanks,
> > Peter
Jay Freedman - 14 Dec 2007 19:11 GMT
Sorry, haven't a clue. Everything I know about the ActiveX controls is in
http://msdn2.microsoft.com/en-us/library/aa140269(office.10).aspx plus the
little bit I've learned from experimenting. The main thing I learned is that
their drawbacks make them mostly not worth using. I'd much rather use the
equivalent controls in a UserForm, which are lighter-weight, more stable,
and easier to program.

> This is great! Thank you so much.
> Do you have any idea why a "1" is getting appended to the field name
[quoted text clipped - 59 lines]
>>> Thanks,
>>> Peter
Peter - 14 Dec 2007 19:25 GMT
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.

> Sorry, haven't a clue. Everything I know about the ActiveX controls is in
> http://msdn2.microsoft.com/en-us/library/aa140269(office.10).aspx plus the
[quoted text clipped - 66 lines]
> >>> Thanks,
> >>> Peter
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.