How to check a checkbox in MS Word?

GaryDGaryD Member Posts: 66
Hello all. In Nav 5.1, we're using automation to populate form fields in a Word 2007 document. We've got the following working for text fields:
WRange := WDoc.Fields.Item(11).Result;
WRange.Text := Sellto."No.";
but I'm not sure of how to check/uncheck a checkbox.

Also, are there any good tutorials or articles out there that cover programming MS Office in NAV?

Thanks!

Comments

  • SavatageSavatage Member Posts: 7,142
    Do you mean other that waht's in the application designers guide?

    Which has sections on MS word & Excel automation.

    As for the check box - do you want to update a check box in nav or show a check box in word?
  • GaryDGaryD Member Posts: 66
    Savatage, yes, other than the application designers guide. It seemed kind of light on the automation coverage. It covered automation of text values but not things like radio buttons, checkboxes, images, manipulating Word tables by adding columns and rows, etc...

    Some of this I've learned already but haven't had the need to update checkboxes until now. I'll restate my issue:
    I have a boolean value in my database, which corresponds to a checkbox in a Word document. In NAV a user clicks a button and NAV opens up the Word document and pre-populates a bunch of the form fields on it. I know how to update the document's text fields but I don't know how to update a checkbox. The checkbox already exists on the Word document, I just want NAV to be able to check it or uncheck it when the document loads, based upon the value of the database field. I'd just like the equivelent of what I do with the textbox when I do:
    WRange := WDoc.Fields.Item(11).Result;
    WRange.Text := Sellto."No.";
    which is populating the Word text field with the content of "No." field from the Customer table.

    Thanks!
  • SavatageSavatage Member Posts: 7,142
    I agree the Office Automation in the ADG isn't very detailed. And lots of trial & error. ](*,)

    When I need a checkbox in Word I use the old Capital "R" with font "Wingdings 2" I don't know if that will help in anyway.
  • GaryDGaryD Member Posts: 66
    Thanks Savatage but that won't work. The checkbox in the Word document is an actual checkbox. It can only be checked or unchecked. I can't put anything else into it. And as the form is also used outside of NAV, I can't redesign it to use your suggestion.
  • GaryDGaryD Member Posts: 66
    One more piece of info that I found out. Looking in MSDN for the FormField object, this is how you change the value of a checkbox:
    ActiveDocument.FormFields("Check1").CheckBox.Value = True

    I don't know if there's a difference between formfields and fields but for count they both returned the number of fields on the document. I've tried coding for each with no success.

    I can do this:
    message(format(wdoc.formfields.count)); // or wdoc.fields.count
    which seems to give me the correct number of fields in the Word document. But perhaps the object library that NAV has access to is stripped down or something because none of the following work
    message(format(wdoc.fields.item(23).result)); // returns "In use"
    message(format(wdoc.formfields.item(23).result)); // returns "A variable was expected" for item(23)
    message(format(wdoc.fields(23).result)); // compiling returns "A max of 0 parameters must be used..."
    message(format(wdoc.Fields.item(23).checkbox.value));
    // compiling returns "You have specified an unknown variable" (for checkbox)
    message(wdoc.formfields.item(21).value); // returns "A variable was expected" for the item(21)
    message(wdoc.formfields.item("Check21").value);
    // returns "a variable was expected" for the "Check21" Word bookmark name

    Bottom line is that formfields.count returns the correct count so I must have accessed the collection but I just can't figure out how to dig down into it to get what I want.
Sign In or Register to comment.