Solved

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

Posted on 2008-06-23
4
811 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

738 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