How do I modify the value of a checkbox in a word document using C

Hi all,
 I am a bit of a newbie at C# and am trying to set up a document that I will 
be modifying based on values from a database.  I am using a word document, 
because it is the "official" reporting form required by my company.  I can 
open the document, and write to bookmarks that I am setting in each table 
field, but I need to know how to manipulate a checkbox.  Can anyone help me?  
I have edited this post because I have added some other code.  The document 
file I am using is a document that has everything inside a table.  I have 
bookmarked all the text locations, and have bookmarked the table cell with 
one of the checkboxes if that helps.  Anyway, below is my code.  I just need 
to know how to tell my program to expect a checkbox at that location, and 
modify it based on the alue of a checkbox in my application.

Thanks in advance for all the help.

Ed


private void CreateWordFile()
        {
            DateTime myDate;
            object oMissing = System.Reflection.Missing.Value;
            object oEndOfDoc = "\\endofdoc";  //\endofdoc is a predifined 
bookmark.

            //Start Word and open template.
            Word._Application oWord;
            Word._Document oDoc;
            oWord = new Word.Application();
            oWord.Visible = true;
            object fileName = @"C:\Plant Tracker\AMP-108_old.doc";
            oDoc = oWord.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);
           
            //Edit Bookmarks in File.
            object oBookMark = "FacNameBkMk";
            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = "Magnolia 
Energy";
            oBookMark = "EventDateBkMk";
            myDate = Convert.ToDateTime(eventDateTxtBx.Text);
            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = 
myDate.ToShortDateString().ToString();
            oBookMark = "EventNumBkMk";
            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = 
eventNoTxtBx.Text;
            oBookMark = "TitleBkMk";
            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = 
titleTxtBx.Text;
            oBookMark = "SummaryBkMk";
            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = 
summaryTxtBx.Text;
            oBookMark = "DetailBkMk";
            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = 
detailTxtBx.Text;
            oBookMark = "RespBkMk";
            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = 
caRespTxtBx.Text;
            oBookMark = "CADueBkMk";
            myDate = Convert.ToDateTime(caDueDateTxtBx.Text);
            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = 
myDate.ToShortDateString().ToString();
            oBookMark = "CorrActBkMk";
            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = 
corrActionTxtBx.Text;
            oBookMark = "PrepByBkMk";
            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = 
prepByTxtBx.Text;
            oBookMark = "PrepDateBkMk";
            myDate = Convert.ToDateTime(prepDateTxtBx.Text);
            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = 
myDate.ToShortDateString().ToString();
            oBookMark = "PMAppBkMk";
            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = 
pmApprovTxtBx.Text;
            oBookMark = "PMDateBkMk";
            myDate = Convert.ToDateTime(pmDateTxtBx.Text);
            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = 
myDate.ToShortDateString().ToString();

            oBookMark = "FinakChkBkMk";
            //How do I access the checkbox that is stored in the table cell 
at this bookmark?

            // Save as new file with file name of "Incident" + EventNumber + 
Date.
            myDate = Convert.ToDateTime(eventDateTxtBx.Text);
            object saveFileName = @"C:\Plant Tracker\Incident_Report_" + 
eventNoTxtBx.Text + "_" + myDate.ToShortDateString().ToString().Replace('/', 
'-');
            MessageBox.Show(saveFileName.ToString());
            oDoc.SaveAs(ref saveFileName, 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);
           


0
Utf
12/7/2009 2:37:01 PM
word.vba.general 1023 articles. 1 followers. Follow

1 Replies
1058 Views

Similar Articles

[PageSpeed] 17

>            oBookMark = "FinakChkBkMk";
>            //How do I access the checkbox that is stored in the table
> cell at this bookmark?

It isn't necessary to add a bookmark to the cell containing the checkbox. 
When you inserted the checkbox in the document, it was automatically 
assigned a name, which is both an ordinary bookmark associated with the 
checkbox and the checkbox's name as a FormField object. If you open the 
document manually, unprotect it (if it's protected), and double-click the 
checkbox, you'll see the name in the Bookmark box of the Properties 
dialog -- and you can change it from the default Check1 to something 
meaningful such as "FinalChk". (You did mean Final and not Finak, right?)

In your code, you can address the checkbox directly like this:

   object oFormField = "FinalChk";
   oDoc.FormFields.get_Item(ref oFormField).CheckBox.Value = True;

or, if you'd rather keep the bookmark you added to the cell, you can go 
indirectly through the Bookmarks collection like this:

   oBookMark = "FinalChkBkMk";
   oDoc.Bookmarks.get_Item(ref oBookMark).Range.FormFields(1).CheckBox.Value 
= True;

-- 
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so 
all may benefit.


Ray wrote:
> Hi all,
> I am a bit of a newbie at C# and am trying to set up a document that
> I will be modifying based on values from a database.  I am using a
> word document, because it is the "official" reporting form required
> by my company.  I can open the document, and write to bookmarks that
> I am setting in each table field, but I need to know how to
> manipulate a checkbox.  Can anyone help me? I have edited this post
> because I have added some other code.  The document file I am using
> is a document that has everything inside a table.  I have bookmarked
> all the text locations, and have bookmarked the table cell with one
> of the checkboxes if that helps.  Anyway, below is my code.  I just
> need to know how to tell my program to expect a checkbox at that
> location, and modify it based on the alue of a checkbox in my
> application.
>
> Thanks in advance for all the help.
>
> Ed
>
>
> private void CreateWordFile()
>        {
>            DateTime myDate;
>            object oMissing = System.Reflection.Missing.Value;
>            object oEndOfDoc = "\\endofdoc";  //\endofdoc is a
> predifined bookmark.
>
>            //Start Word and open template.
>            Word._Application oWord;
>            Word._Document oDoc;
>            oWord = new Word.Application();
>            oWord.Visible = true;
>            object fileName = @"C:\Plant Tracker\AMP-108_old.doc";
>            oDoc = oWord.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);
>
>            //Edit Bookmarks in File.
>            object oBookMark = "FacNameBkMk";
>            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
> "Magnolia Energy";
>            oBookMark = "EventDateBkMk";
>            myDate = Convert.ToDateTime(eventDateTxtBx.Text);
>            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
> myDate.ToShortDateString().ToString();
>            oBookMark = "EventNumBkMk";
>            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
> eventNoTxtBx.Text;
>            oBookMark = "TitleBkMk";
>            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
> titleTxtBx.Text;
>            oBookMark = "SummaryBkMk";
>            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
> summaryTxtBx.Text;
>            oBookMark = "DetailBkMk";
>            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
> detailTxtBx.Text;
>            oBookMark = "RespBkMk";
>            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
> caRespTxtBx.Text;
>            oBookMark = "CADueBkMk";
>            myDate = Convert.ToDateTime(caDueDateTxtBx.Text);
>            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
> myDate.ToShortDateString().ToString();
>            oBookMark = "CorrActBkMk";
>            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
> corrActionTxtBx.Text;
>            oBookMark = "PrepByBkMk";
>            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
> prepByTxtBx.Text;
>            oBookMark = "PrepDateBkMk";
>            myDate = Convert.ToDateTime(prepDateTxtBx.Text);
>            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
> myDate.ToShortDateString().ToString();
>            oBookMark = "PMAppBkMk";
>            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
> pmApprovTxtBx.Text;
>            oBookMark = "PMDateBkMk";
>            myDate = Convert.ToDateTime(pmDateTxtBx.Text);
>            oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
> myDate.ToShortDateString().ToString();
>
>            oBookMark = "FinakChkBkMk";
>            //How do I access the checkbox that is stored in the table
> cell at this bookmark?
>
>            // Save as new file with file name of "Incident" +
> EventNumber + Date.
>            myDate = Convert.ToDateTime(eventDateTxtBx.Text);
>            object saveFileName = @"C:\Plant Tracker\Incident_Report_"
> + eventNoTxtBx.Text + "_" +
> myDate.ToShortDateString().ToString().Replace('/', '-');
>            MessageBox.Show(saveFileName.ToString());
>            oDoc.SaveAs(ref saveFileName, 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); 


0
Jay
12/7/2009 3:36:56 PM
Reply:

Similar Artilces:

Track Changes with Copy/Paste
I have a user who uses Track Changes. Sometimes he copies/pastes that info into a new document and the 'track changes' feature remains active and working in the new document, which he likes. However, sometimes the Track Changes settings don't carry over to the new document. How can he copy/paste from a document where Track Changes is being used so that the Track Changes feature/settings carry over to the new document? Thank you. See http://www.shaunakelly.com/word/trackchanges/HowTrackChangesWorks.html#Copying for a description of the rules that apply when cop...

Help with using data
Hi I would really appreciate some help with extracting data from Outlook. I have been building up a database of clients/prospectives, these are in various categories. I would like to extract/search on various fields as well as my own categories, all i can do with export is extract the whole lot to a tab delimited file. Or export categories to an rge file which I can't use. Any ideas out there? thanks Outlook's Search doesn't suffice? There are 3rd party search applications that might help. What sprcifically stops you from exporting to a format other than TSV? There are other...

Run-time error 438
I'm trying to find out why this code is not working. With Worksheets("Multi-period Code data").ListBox1 .Clear For FillCount = 1 To Worksheets("ClassCodes").Range("E1") .AddItem Worksheets("ClassCodes").Range("C1").Offset(FillCount, 0) Next FillCount .ListIndex = Worksheets("Multi-period Code data").Range("O1").Value End With Just to clarify, there is a sheet named "Multi-period Code data" and ListBox1 exists on the sheet. The err...

Software recommendations for Document Control, CAPA and PLM
My company is looking for third party software for Document Control, CAPA and PLM. If any of you have any recommendations, please post. It will be nice if these softwares could interface with Great Plains. Stacey ...

Deleting N/A value in a spreadsheet with V-Look Up
Hi I have a large spreadsheet of Data that contains a Vlook up to anothe sheet. I need to sum the figures however the V-Look up is returnin some N/A values which the autosum doen't recognize. How do I delet these or make them equal to zero? thanks -- JOConno ----------------------------------------------------------------------- JOConnor's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1661 View this thread: http://www.excelforum.com/showthread.php?threadid=31482 Hi you may change your formulas to =IF(ISNA(VLOOKUP(...)),"",VLOOKUP(...)) or for...

Real Programmers (TM) use MSFT C# not Linux languages (sez an expert)
Don't take my word for it, see what this nationally syndicated author and computer programming guru says... and note the reader's comment at the very end...about Linux...I think he's talking about Linux. Anyway the takeaway executive summary of this article is simple: C# rulz. RL http://programmingzen.com/2010/06/23/how-microsoft-is-changing-the-programm= ing-world/ How Microsoft is changing the programming world Posted on Jun 23rd, 2010 in .NET, Programming Languages | 47 comments Several years ago I knew a programmer, we=92ll call him Joe, who fancied himsel...

Good document management software?
Does anyone have any experience with document management software that works with GP? We're looking for something that works with GP-generated files as well as external documents that we need to scan and store. I've found the following via web searches: - KwikTag - doc-link - ImageLink - PaperVision Integration - PaperSave - GPx - docAssist - ImageNow Anyone out there use these...or do you know of any others you could recommend? -- Bud Cool Microsoft Certified Business Management Solutions Specialist, GP 9.0 Financials Currently supporting: GP 9.0, SP2 Bud, We partner with Pa...

Color documents are printing in black and white only. Why?
I've recently upgraded to the newest Publisher version and I hate it. I have been unable to print any document in color...no matter what it looks like on screen, in a print preview, and when I print, it is in greyscale/black and white. Help! Check your settings within the printer setup. -- JoAnn Paules MVP Microsoft [Publisher] Tech Editor for "Microsoft Publisher 2007 For Dummies" "Bobbyesox" <Bobbyesox@discussions.microsoft.com> wrote in message news:CDE46E92-EC6D-40F2-8244-FA71F7C4D275@microsoft.com... > I've recently upgraded to the newest Pub...

Outlook 2003 error when trying to use WordMail
Hi, Outlook 2003 has recently started reporting the following error, when trying to use Word 2003 as the MAil Editor. I have tried all the uslal things including Uninstalling Office, clearing the main registry settings and re installing, but nothing seems to work, does anyone have any idea what is causing this and more importantly how to solve it: "Word is unavailable, not installed, or is not the same version as outlook. The outlook email word editor will be used instead. an OLE registration error occured. The program is not correctly installed run Setup program again" Gavin,...

zero values become negative notation
1 value of a cell minus another similar value of another cell = a negative value with a negative notation power. Is this a bug? Maybe the two values are not exactly the same. Could this be IEEE round-off error? Chip's clear explanation http://www.cpearson.com/excel/rounding.htm Floating-point arithmetic may give inaccurate results in Excel http://support.microsoft.com/kb/78113/en-us (Complete) Tutorial to Understand IEEE Floating-Point Errors http://support.microsoft.com/kb/42980 What Every Computer Scientist Should Know About Floating Point http://docs.sun.com/source/806-3568/...

Query--using Access 2007
I have a tblAddress table with a lookup field called TypeofAddressID. A company may have many addresses with different TypeofAddressID—such as 1 = Business, 2 = Mailstop, 3 = PO Box, and so on. I need to pull out TypeofAddressID # 1. Then if a 1 is not available, give me the type that is (which may be the PO address or Mailstop). I tried DLookup, Xor, and IIf([TypeofAddressID]=1, 1, IIf([TypeofAddressID]=2, 2, IIf([TypeofAddressID]=3, 3, 4))), but it is listing all addresses per company instead of either or. Any suggestions? -- Message posted via http://www.accessmonster....

sending document content to excel to open it
Hi! I'd like to write an application that stores excel-sheets in a database. Now I need to open that document, but i don't want to buffer it on the harddisc, because that's confidental data. Thanks for support Joe ...

GP should provide audit trail for GL objects/records modified
In order to comply with SOX (and internal company auditability & traceability), it would be beneficial if Great Plains provided audit trail(s) for modifications of General Ledger records, including userid (last modified date is already recorded in Item Master table). This could apply to inventory items, purchase orders, batches, and other journal entries. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the...

Customizing MailMerge Document Creation
I've been experimenting with creating quotes using the WordMailMerge add-on, as well as using the in-built mail merge functionality with CRM 3.0, and one issue has me perplexed- When I edit the template for the Mail Merge, I can't seem to customize certain fields that only populate once the merge is completed (e.g. outgoing address text box). Additionally, where in the template is it built-in to create a separate line for each product on the quote and pull the records from CRM for each of those quotes? When I write a template from scratch to resolve the first issue, I can't figure...

If formula that looks at multiple cells and values, and then calul
I'm trying to put together a production spreadsheet for mechanical manufacturing that figures out a length of one piece of material based on other dimensions. It's for storm shutter parts and the cut dimensions need to be calculated from the field measures. There are many types of tracks available and the blade length is dependant upon the finish height, track type and structure. I need the formula to look at 5 different cells that may or may not have data for the top track and only use the data from the one that's filled out. Same for the bottom track for a total of 10 ...

how can I enter 453. to show as 453 instead of 4.53 when using th.
I'm not sure how to use the decimal when entering numbers in excel. I want to use the fixed decimal space as to so when I just type in 453 it appears as 4.53 But when I want to enter 60 and I enter 60. I get .60 Any thoughts? Enter 60. with the decimal point at the end. In article <B343D637-7039-48CA-AB16-6B389D3A441A@microsoft.com>, "Scott" <Scott@discussions.microsoft.com> wrote: > I'm not sure how to use the decimal when entering numbers in excel. I want > to use the fixed decimal space as to so when I just type in 453 it appears as >...

I cant use englisch function names in a swedich version of excel
Hi, Why can't I use Englisch named function names, like =ROUND(...) in a sheet when I have a Swedich version of excel. Excel will tell me the error "#Name?" when I open an Englisch version worksheet or if I try to enter an englisch function name. But if I write a macro with the englisch function name inside the code and I call that macro in the sheet the function will be translated to the swedich function name. Thanks Pelle Hi this is just the way Excel works. For a function translation see: http://www.contextures.com/functions.html -- Regards Frank Kabel Frankfurt, Germany ...

VALUES ARE DIFFERENT THAN CALCULATOR
I am figuring my payroll on an Excel spreadsheet. When I enter the formulas, the values are sometimes off by a penny. On my calculator, I have it set to 5/4. How do I get my formulas to come out the same as the calculator? Look in help for the ROUND function Also see link for discussion of rounding issues http://www.cpearson.com/excel/rounding.htm "Jaime" wrote: > I am figuring my payroll on an Excel spreadsheet. When I enter the formulas, > the values are sometimes off by a penny. On my calculator, I have it set to > 5/4. How do I get my formulas to come out...

How can I enlarge a picture on word/document and print it?
Might be a 'Drawing and Graphics' question. Hello Ruben Ruben wrote: > Might be a 'Drawing and Graphics' question. yes, it might ... :-) You don't say with which part you are having trouble, but I suppose it's the enlarging; usually, you simply click and hold on any picture corner and drag. If that doesn't work, please specify what kind of picture in what kind of document, version of Word, etc. HTH Robert -- /"\ ASCII Ribbon Campaign | MSFT | \ / | MVP | Scientific Reports X Against HTML ...

Merging Data into Word and Want Checkboxes (Yes/No data type)
I am trying to merge data from my access database into word. I have several items that are checkboxes in access. How do i get those checkboxes to merge into word so that i see them. Right now they just produce numbers if they are checked or not. Thanks I'm not sure you can do with with a straight mail merge. The following is a snippet of code from one of my applications. The app relies on documents that have already been bookmarked with simple bookmarks (for fields longer than 255 characters), checkboxes (for y/n fields), and textboxes for everything else. The merging is d...

How to Insert clips in Outlook using Clip Art Organizer
My Outlook 2003 "Insert" menu used to have the option of using the Clip Art Organizer program to search for clip art to insert into Outlook. This option has disappeared and I have not been able to find out how to get it back. Any ideas? "Tamara" <Tamara@discussions.microsoft.com> wrote in message news:CADF265E-7DBB-46EB-8077-CA78137FE4C3@microsoft.com... > My Outlook 2003 "Insert" menu used to have the option of using the Clip Art > Organizer program to search for clip art to insert into Outlook. This > option > has disappeare...

Transfer from file to document very slow
I take about 40 seconds for the document to come up on screen This also happens in Word It is impossible to provide a concrete suggestion with so little information. The slow opening of a file could be due to any and all of the following as well as many other factors. Insufficient RAM to hold the large file leads to numerous time-consuming saves to virtual memory. A virus protection program to blocking the opening of the file until it has completed a virus threat check on the file. Other applications are hogging machine resources. A potential resource hogging application may be a ...

WHERE without using CASE
I'm trying to edit a Filter in Outlook and it has a sort of SQL syntax. The only thing is I don't know if it accepts CASE statements -- it's giving a 'SQL parsing' error. Is there another simple SQL way of doing this WHERE clause without using case (e.g. using AND or OR)?: WHERE (CASE WHEN (MyField1 IS NULL) THEN (MyField2) ELSE (MyField1))>1 My Reference: (CASE WHEN ("http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/MyField1" IS NULL) THEN ("http://schemas.microsoft.com/mapi/st...

How do I use the data in a named field to select a worksheet tab .
I need to use a named field to select a worksheet tab in another workbook. ie i have a workbook called Master and need to collect data from a workbook called Reports, but i need to collect it from different worksheets within Reports depending on the month selected in Master. The tabs in Reports are M01,M02,etc. In Master I have a Named Field called 'Month" with M01,M02 etc entered in it. This field needs to select the corresponding tab in Reports. Usually the reference syntax goes something like '[Filename]Tabname!Cellname or reference. Here is an obscure example from an old...

Excel to Word mail merge problem
I am having a problem with a mail merge document taking data from and Excel worksheet. The data includes currency values. Trailing zeros are not appearing meaning that 147.50 appears as 147.5. How can I make it read 147.50 in the Word document? TIA Ian In the Mail Merge, after you select your Excel file as a data source, you should see a 'Confirm Data Source' dialog box. (If you don't see the dialog box, change the setting in Word -- under Tools>Options, General -- add a check mark to 'Confirm Conversion at Open') From that list, choose 'MS Ex...