Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check a checkbox ??

Status
Not open for further replies.

doneirik

Technical User
Nov 23, 2007
30
NL
Hi,

...sounds like a simple question...well, explanation:

I have 3 checkboxes labelled "CLASS 1", "CLASS 2", "CLASS 3".
I also have a custom property in my document named "CLASS", the value of this property is...class1, class2 or class3. this property is not visible for users.

(I am using an external program to modify some fields, thats the reason)

Now, is there a way that word can read the value of the text-property and check the correct checkbox based on the content of that field?

regards
d.
 
Most likely....yes.

What kind of checkbox?

When you say "custom property", is this a custom document property, or a document Variable? I ask, because you state it is not visible to the user. If it is a document propery then it normally WOULD be visible.



faq219-2884

Gerry
My paintings and sculpture
 
Thanks Gerry,

I misspoke.. When I said "not visible to the user" I should have written "not visible on the print-area of the document". Of course by clicking on properties the user will see it.

The checkbox is a checkbox in MS Word (by using Forms) This is the only checkbox I can insert...at least as far as I know.

So basically, what I want is a way to check one, but only one of 3 checkboxes depending on the text value in a forth field.

regards
d.
 
A simple Select Case statement should do it.

I asked about what kind of checkbox because there are TWO checkboxes you can insert. One using the Forms toolbar (which is a formfield...and what you have done); the other using the Controls toolbar. These are ActiveX checkboxes, and are quite different than formfields.

I state a simple Select Case should do it, and it can. However, I am wondering WHY you are doing this? What exactly is the point? A user can check/uncheck the checkbox..any of them.

What exactly are you trying to accomplish?
So basically, what I want is a way to check one, but only one of 3 checkboxes depending on the text value in a forth field.
Hmmmm. These are different things. Calling it a "fourth" field is a misnomer. Formfields are actual things in a document. A custom property is not, really, a field. It can be put in a field, but it is, well, a document property.

A straightforward Select Case statement would be easy to write...but I have to ask you to think it through. Only because I don't know what you are really doing with your document.

Say you have Class2 in your custom property.
Code:
Sub YaddaYaddaBlah()
Select Case ActiveDocument.CustomDocumentProperties("Class")
   Case "Class1"
      ActiveDocument.FormFields("Check1").CheckBox.Value = True
   Case "Class2"
      ActiveDocument.FormFields("Check2").CheckBox.Value = True
   Case "Class3"
      ActiveDocument.FormFields("Check3").CheckBox.Value = True
End Select
End Sub
OK, that is straightforward. If Class = "Class2", the Class2 formfield gets checked.

But - and again I don't know what is really happening - it would NOT uncheck the others, if they were checked. AND, there is absolutely nothing to stop the user from checking all the other, OR unchecking the Class2 checkbox.

So say the Class property was Class1 before, you change it to Class2, and run the code. Sure it will check Class2...but it will not uncheck Class1. Can you do that? Of course. Easy. What I am asking is what EXACTLY is the logic and purpose behind this?

As this could be (and probably is) a VBA question, you should likely re-post this into the VBA forum. However, to answer your question:
Now, is there a way that word can read the value of the text-property and check the correct checkbox based on the content of that field?

Yes, there is a way. There ya go.

faq219-2884

Gerry
My paintings and sculpture
 
Thanks,

as to what I´m doing this for...I have a SW suite for revision control and document management holding the Office Files. This SW has a graphical user interface making it possible to easily modify the contents of properties in Office documents.
The stuff I need to implement is implemented with radiobuttons in this SW...as I did not find radiobuttons as a form field I try to implement this with checkboxes, i.e. the caption of the clicked radiobutton in my external SW is transferred to a property in MS word, which in turn check / uncheck the corresponding checkboxes.

...thats it...

regards

d.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top