Solved

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

Posted on 2008-06-23
4
795 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now