Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-06-23
4
Medium Priority
?
827 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 750 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

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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 and create new code templates in NetBeans IDE 8.0 for Windows.

722 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