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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interactive Check Boxes

Status
Not open for further replies.

silcox1984

Technical User
Mar 12, 2008
18
US
I am very new to VBA and I am not sure this is what I need to complete my task.

I would like to make my checkboxes interactive using microsoft word. I was told I would need to use VBA in order to do so.

I want to be able to choose an option from a dropdown list and in doing so would enable drop down choices.

For example:
Red
Green
Yellow
Blue

I would pick Red
and a Check box would appear to say "Yes" and a check box would appear to say "no"

Is this possible?

Thank you
 
What are you trying to achieve? Are you changing font colors or...

"I would pick Red
and a Check box would appear to say "Yes" and a check box would appear to say "no"

Give a bit more info.
 




I would pick Red
and a Check box would appear to say "Yes" and a check box would appear to say "no"

Would another way of saying that be, selecting "red" in the combobox would cause TWO checkboxes to be made visible: One with a caption of "Yes" and the other with a caption of "No"?


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Yes.


Essentially what i am trying to do is have usable check boxes appear or disappear on a form depending on choices i make throughout the document.

"Would another way of saying that be, selecting "red" in the combobox would cause TWO checkboxes to be made visible: One with a caption of "Yes" and the other with a caption of "No"?"
EXACTLY.
 




Check out the Visible property.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Im sorry, I do not know what you mean by that. I was told to visit the VBA forum for answers to my questions. Are you saying this is not a VBA solvable problem?
 




Check out the Viaible property of the CheckBox Object. That's how you, "have usable check boxes appear or disappear on a form."

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
1. This is why I answered "yes", with no further information. I could not, as no further information was given.

2. Skip suggests using Visible...and not to disparage Skip (who would dare????), but it it is exactly the same thing as #1 above. Not enough information. Skip is making his suggestion based on an assumption, NOT information.

The Visible property does not exist for checkboxes in a document. Neither formfield checkboxes (using the Forms toolbar), nor ActiveX checkboxes (using the Controls toolbar) have a Visible property.

Checkboxes on a userform have a Visible property - thus, Skip made an assumption that you are asking about checkboxes on a userform. It is that "form" word. It is - unfortunately - very badly used in communication. Be VERY careful, and very explicit!, when using the word "form".

I suspect - but agreed, I do not not know...which is, again, why I simply answered "Yes" - that you are using formfield checkboxes in the document.

And, again, the answer to "Is this possible?" is Yes. However, much better, accurate details on your requirements, and precisely what you wish to do, including precise logic, are required.

Also, a clear understanding of WHY you wish to do this, but the answer is a Yes. A qualified Yes.

Qualified? Yes qualified, because, as there is no Visible property, work-arounds (and there are a few) can do things like make a checkbox Height and Width = 1, thus essentially making it...invisible. I have done this. This option will ONLY work for ActiveX controls (checkboxes). This option will NOT work for formfield checkboxes.

And....just to belabor the point...you have not stated what kind of checkboxes you are using....

Nor have you clearly stated your logic requirements. For example, if the user goes back and changes the selection from the combobox - and do you mean dropdown???? - is it a requirement that the checkboxes go away? You do not say.

Other work-arounds can be making text (the paragraph containing the checkbox) Hidden. That works but is IMO sloppy. Other options can be to dynamically delete/recreate the checkboxes depending on the logic.

So...again. "Is this possible?"




Yes.

Here is an very simple (logically speaking) example.
Code:
 If ActiveDocument.FormFields("Colours").Result = "  red  " Then
    CheckBox1.Height = 18.5
    CheckBox1.Width = 108
    CheckBox2.Height = 18.5
    CheckBox2.Width = 108
Else
    CheckBox1.Height = 1
    CheckBox1.Width = 1
    CheckBox2.Height = 1
    CheckBox2.Width = 1
End If
There is a formfield DropDown named "Colours". In my test it has " blue ", " black ", " green " and " red ", as the dropdown items.

Note the spaces in the item strings.

The code executes when you exit the Colours formfield, using the OnExit macro.

If " red " is the Result (i.e. red is selected from the dropdown), THEN 2 ActiveX checkboxes (Checkbox1, and Checkbox2 - use better names!!!!) are resized to 18.5 in Height, and 108 in Width, thus...becoming "visible".

ELSE (i.e red is NOT selected)
THEN the checkboxes are explicitly set to 1 in both Height and Width, essentially becoming invisible.

The above uses both formfields (the dropdown) and ActiveX controls (the checkboxes), but it could use ActiveX for all of them.

If your checkboxes are formfields, the above will NOT work, as you can not dynamically resize them.

There are, again, other possibilities - so the answer IS....Yes, but you would have to give real details of what you have, and what you want to happen.

faq219-2884

Gerry
My paintings and sculpture
 
Ok. Then let me start over.

I am creating a template in microsoft Word for my job. I am familiar with making locked documents using form field equations like If X = Yes then X will appear on the document. I am unfamiliar with using the checkbox function on the form field. I would like it to be as interactive as the dropdown and block text form fields are. I would like to create a document in microsoft word using interactive checkboxes. I was told (by another responder to this forum) that the only way to accomplish this would be by using VBA. Instead of using colors i will give you the real world example:

using Microsoft word 2003 I am attempting to create an interactive checklist. My colleagues would pick from a list (created by dropdown form field) the project they are working on. Depending on that project, (and the choice they picked) i would like empty (but usable) checkboxes to appear.

So if they picked that they are working on the Excel project, two empty but usable check boxes would appear saying either Formulas? (Checkbox) Graphs ?(Checkbox). However, if someone else is working with Outlook, and that is the choice they made two checkboxes would appear that say: Email? (checkbox) Calendar? (Checkbox).


HOW can i make this work?
 
HOW can i make this work?"

Re-read my post. But I will go through it again.

1. make your dropdown formfield, with its items.
2. write an OnExit macro for the dropdown.
3. when the user makes a selection from the dropdown list, and moves on, the OnExit macro fires.
4. the OnExit macro will either:

a) do a resizing of existing ActiveX checkboxes
OR
b) create NEW checkboxes

Below is an example of a) - resizing of checkboxes. I would do it as a Select Case on the result of the dropdown.
Code:
 Sub MyOnExit() ' for the dropdown
Select Case [i]dropdown.name[/i].Result
   Case "Excel"
       Call ShowExcel
   Case "Outlook"
       Call ShowOutlook
   Case [i]other choices[/i]
End Select
End Sub


Sub ShowExcel()
    CheckBox1.Height = 18.5
    CheckBox1.Width = 108
    CheckBox1.Caption = "Formula?"
    CheckBox2.Height = 18.5
    CheckBox2.Width = 108
    CheckBox2.Caption = "Graphs?"
End Sub

Sub ShowOutlook()
    CheckBox1.Height = 18.5
    CheckBox1.Width = 108
    CheckBox1.Caption = "Email?"
    CheckBox2.Height = 18.5
    CheckBox2.Width = 108
    CheckBox2.Caption = "Calendar?"
End Sub

So, if they choose "Excel" from the dropdown, then the checkbox Captions show as "Formula?" and "Graphs?"

If they choose "Outlook" from the dropdown, then the checkbox Captions show as "Email?" and "Calendar?"

I just did this, and it works fine.

You will, of course, have to work out the logic for the checkboxes! Something like:
Code:
Sub CheckBox1_Change()
   Select Case CheckBox1.Caption
      Case "Formula?"
          ' do what ever it is
          ' for the Excel choice
      Case "Email?"
          ' do what ever it is
          ' for the Outlook choice
'      Case  [i]other choices[/i]
         ' and whatever
   End Select
End Sub
You did not answer the question I asked about whether you may want the checkboxes to go away. If you do not...why do you want them to be "invisible" in the first place?

Frankly, although i am not clear of your requirements, it may be better/easier to do this on a userform, rather than in the document.

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top