Link to home
Start Free TrialLog in
Avatar of SSSoftware
SSSoftware

asked on

How to retrieve the checked status from an OCX checkbox on a MS-Word 2003 Fillin Form

I have a MS-Word 2003 Fillin Form with an active Checkbox OCX on it. I need to retrieve the status of the Checkbox and save it in a database.
I have been unable to retrieve the checkbox Status (Checked,Unchecked) using VB.Net 2005

Using the Fields collection I can access the checkbox as a WdFieldType.wdFieldOCX type but am unable to retrieve the checked status or the name of the field.

There has to be an easier way to retrieve the information than the way I am attempting.

The code snippet transverses the "Fields" collection and selects the fields that are OCXs.

'---------------------------
Option Strict On
Option Explicit On
 
Imports Word = Microsoft.Office.Interop.Word
Imports WordFieldType = Microsoft.Office.Interop.Word.WdFieldType
 
'-----------------------------
' m.WordDoc is the document I am interrigating
'-----------------------------
 
            For Each F As Word.Field In m.WordDoc.Fields
                Debug.WriteLine("Fields - " & F.Type.ToString)
                Dim wdFieldType1 As Microsoft.Office.Interop.Word.WdFieldType = Microsoft.Office.Interop.Word.WdFieldType.wdFieldOCX
                Dim FieldOCX As Microsoft.Office.Interop.Word.Field
 
                If F.Type = Word.WdFieldType.wdFieldOCX Then
                    FieldOCX = DirectCast(F, Microsoft.Office.Interop.Word.Field)
                    Debug.WriteLine(FieldOCX.Result)
                    Debug.WriteLine(FieldOCX.Result.Text)
                    Debug.WriteLine(FieldOCX.Result.FormattedText)
                    Dim RG As Microsoft.Office.Interop.Word.Range
                    RG = FieldOCX.Code
                    Debug.WriteLine(RG.Text)
                    Debug.WriteLine(RG.FormFields)
                End If
            Next F

Open in new window

Avatar of Christopher Kile
Christopher Kile
Flag of United States of America image

Build a COM object wrapper around the code necessary to post this info to the database.  This is VERY easily done with VS 2005 in any of its languages.

http://msdn.microsoft.com/en-us/library/ms973802.aspx

If you need clarification, additional resources, or other help on this issue, drop a note here and I'll be glad to help.
Avatar of SSSoftware
SSSoftware

ASKER

Dear  cpkilekofp;
That seems a bit of overkill for  what I want to do.  
Lets go on the assumprion that since MS-Word developers allow you to put OCX controlls on their forms ( it is a MS OCX not a user OCX).
Since they allow that, it follows that they would provide an easy yay to retrieve the current properties of the control.
If you look at the code snippet you can see that I can get to the control.
I just can't figure out how to get the contols properties.

Thanks for the support,
Ed

ASKER CERTIFIED SOLUTION
Avatar of Christopher Kile
Christopher Kile
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Active X controls do seem to be persistant. I did a end run and saved to selection in a variable and then I was able to interrigate the variable.
Thanks for your help.