HELP - Check box form fields, C#, Word 2003

P

pRobinson

I have been stuck on this for a few days....

I have created a windows application (ie windows form) which calls to a Word
Doc. and opens the document and extracts text from tables cells.

I'm having problems getting the check box object and extracting the value
ie: if it's checked or not.

Here is an example of what i have so far....

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Reflection;
using System.Windows.Forms;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Word;
using Microsoft.Office.Tools;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Word = Microsoft.Office.Interop.Word;


namespace WordConvert
{
public partial class frmMaster : Form
{

Object oMissing = System.Reflection.Missing.Value;
Object oEndOfDocument = "\\endofdocuemnt";
object fileName = @"C:\MyDoc.DOC";

Word._Application oWord;
Word.Document oDocument;
Word.Table oTable;
Word.CheckBox oCheckBox;
//Word.FormField oCheckBox;

public frmMaster()
{
InitializeComponent();
}

private void btnRunWord_Click(object sender, System.EventArgs e)
{

oWord = new Word.Application();

oWord.Application.Documents.Open(ref fileName,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

oDocument = oWord.ActiveDocument;
oTable = oDocument.Tables[1];

lblReference1.Text = oTable.Cell(1, 1).Range.Text.ToString();
lblReference2.Text = oTable.Cell(1, 2).Range.Text.ToString();

******// THIS IS WHERE I'M STUCK*******

if (oDocument.FormFields.get_Item(ref oCheckBox).CheckBox.Value == true)
{
chkTest.Checked = true;
}
}

}
}

Any help would be greatly appreciated. Just heads up I'm opening a word
document FROM a windows FORM and not from within the VS 2005 IDE environment.
 
C

Cindy M -WordMVP-

Hi Peter,

This checkbox was inserted from the FORMS toolbar? Not the Controls Toolbox?
Then you need the string name of the checkbox as the index for the Forms
collection. Roughly

object oCheckbox = "CheckboxName"
if (oDocument.FormFields.get_Item(ref oCheckBox).CheckBox.Value == true)
I have created a windows application (ie windows form) which calls to a Word
Doc. and opens the document and extracts text from tables cells.

I'm having problems getting the check box object and extracting the value
ie: if it's checked or not.

Here is an example of what i have so far....

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Reflection;
using System.Windows.Forms;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Word;
using Microsoft.Office.Tools;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Word = Microsoft.Office.Interop.Word;


namespace WordConvert
{
public partial class frmMaster : Form
{

Object oMissing = System.Reflection.Missing.Value;
Object oEndOfDocument = "\\endofdocuemnt";
object fileName = @"C:\MyDoc.DOC";

Word._Application oWord;
Word.Document oDocument;
Word.Table oTable;
Word.CheckBox oCheckBox;
//Word.FormField oCheckBox;

public frmMaster()
{
InitializeComponent();
}

private void btnRunWord_Click(object sender, System.EventArgs e)
{

oWord = new Word.Application();

oWord.Application.Documents.Open(ref fileName,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

oDocument = oWord.ActiveDocument;
oTable = oDocument.Tables[1];

lblReference1.Text = oTable.Cell(1, 1).Range.Text.ToString();
lblReference2.Text = oTable.Cell(1, 2).Range.Text.ToString();

******// THIS IS WHERE I'M STUCK*******

if (oDocument.FormFields.get_Item(ref oCheckBox).CheckBox.Value == true)
{
chkTest.Checked = true;
}
}

}
}

Any help would be greatly appreciated. Just heads up I'm opening a word
document FROM a windows FORM and not from within the VS 2005 IDE environment.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
P

pRobinson

Cindy

A huge thank you for us with this problem. You're solution was 100% on the
money, and as a result you have saved us weeks np months of data enrty.

Thanks again
--
Peter Robinson


Cindy M -WordMVP- said:
Hi Peter,

This checkbox was inserted from the FORMS toolbar? Not the Controls Toolbox?
Then you need the string name of the checkbox as the index for the Forms
collection. Roughly

object oCheckbox = "CheckboxName"
if (oDocument.FormFields.get_Item(ref oCheckBox).CheckBox.Value == true)
I have created a windows application (ie windows form) which calls to a Word
Doc. and opens the document and extracts text from tables cells.

I'm having problems getting the check box object and extracting the value
ie: if it's checked or not.

Here is an example of what i have so far....

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Reflection;
using System.Windows.Forms;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Word;
using Microsoft.Office.Tools;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Word = Microsoft.Office.Interop.Word;


namespace WordConvert
{
public partial class frmMaster : Form
{

Object oMissing = System.Reflection.Missing.Value;
Object oEndOfDocument = "\\endofdocuemnt";
object fileName = @"C:\MyDoc.DOC";

Word._Application oWord;
Word.Document oDocument;
Word.Table oTable;
Word.CheckBox oCheckBox;
//Word.FormField oCheckBox;

public frmMaster()
{
InitializeComponent();
}

private void btnRunWord_Click(object sender, System.EventArgs e)
{

oWord = new Word.Application();

oWord.Application.Documents.Open(ref fileName,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

oDocument = oWord.ActiveDocument;
oTable = oDocument.Tables[1];

lblReference1.Text = oTable.Cell(1, 1).Range.Text.ToString();
lblReference2.Text = oTable.Cell(1, 2).Range.Text.ToString();

******// THIS IS WHERE I'M STUCK*******

if (oDocument.FormFields.get_Item(ref oCheckBox).CheckBox.Value == true)
{
chkTest.Checked = true;
}
}

}
}

Any help would be greatly appreciated. Just heads up I'm opening a word
document FROM a windows FORM and not from within the VS 2005 IDE environment.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)


This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
Top