Solved

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

Posted on 2008-06-23
4
802 Views
Last Modified: 2013-11-26
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

0
Comment
Question by:SSSoftware
  • 2
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 21848124
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.
0
 
LVL 4

Author Comment

by:SSSoftware
ID: 21850365
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

0
 
LVL 23

Accepted Solution

by:
Christopher Kile earned 250 total points
ID: 21856051
SSoftware,

I have been using VBA in the Office applications since before they all used the same dialect; my first Word Basic project involved parsing a .DOC generated by an OCR scanner, and the date of that effort precedes the release date of Windows 95; in all that time, I have yet to run into a working version of the method you describe.  That's not to say your way is impossible, but the .DOC format wasn't even published until this year (or late last year) so no sanctioned method existed for doing it, I've never heard or read about anyone successfully doing it, and it's just NOT the way a VBA programmer would do it.  The method I describe is the way I would do it based on my previous and current experience.  

The problem is that, as far as I know, controls in user forms do not persist their data to the .DOC.  So, you'll see the control reference, but the data properties (being strictly runtime properties) are set by code and not restored from or saved to any persistent store in the .DOC, so there's no place to look for them.  I believe this is different for controls embedded directly in the .DOC itself (NOT in a user form) but that's not the situation you describe.

Naturally, as usual, I'd be fascinated to see someone prove me wrong, but in this case I have high confidence that that will not happen.
0
 
LVL 4

Author Closing Comment

by:SSSoftware
ID: 31469789
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.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question