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
Solved

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

Posted on 2008-06-23
4
805 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

789 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