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

How to Hide a checkbox formfield and change the back color ..

Status
Not open for further replies.

BJ1106

Programmer
Aug 24, 2006
30
US
Hi,

Questions 1:
I am having 2 check box formfields in a Word template. when user entered different infor, there is one checkbox need to be hidden. How can do this?

Question 2:
By default the text form field's background color is gray, can i change it to other colors?

Thanks for any help.
 
Needs" to be hidden? You mean you would like to hide it. I have found that things like checkboxes rarely "need" to be hidden. WHY do you need to hide it? This usually can be affected by different design.

In any case....

1. You can not "hide" a formfield. You CAN apply Hidden font to it, but it becomes visible if someone has the Show/Hide button toggled to Show...so frankly, it is not much use.

Even an ActiveX checkbox control does not have a Visible property. Although it does have the ability to be resized. I have made checkboxes (or other controls) become "hidden" by resizing them dynamically (down to 1 x 1 pixel). Although, as I stated, this is rarely good design.

2. No. But you can turn it to nothing, that is, no shading at all. On the Forms toolbar, click the Form Field Shading button. It is commonly the third button from the right. It is a toggle.

If the intent is to dynamically make checkboxes available, and I assume you are doing this by code - since there appears to be a decision/logic aspect - then you may want to consider creating the checkboxes dynamically.

Gerry
My paintings and sculpture
 
the reason I need to hide one check box is because the template is using by user now. it has check boxes for user to choose.
Now user wants to type in a date to decide: if the date they entered is before 11/1/2006, they still want to see the 2 check boxes, but if after that day, they don't want to see the second check box. once they save the file, next time when they open it, they still can chage the date, which mean they still need to see 2 check boxes. that's why i try to hide one not delete it.

and the description with each checkbox they also want to change based on the date, so i use a text box but not allow user to enter infor, but they want to see the infrom in the text box without gray color. I am also using text boxes in this template to let use enter infor, for example, the date. so if i turn the shading off, they won't see other text boxes.

:((((

 
I guess maybe the best way to slove the checkbox issue is delete it when user entered date less than 11/1/2006, then add it back when the date is > 11/1/2006.

do you know how to add the check box next to a text formfield?

thanks
 
These are design issues.

If I understand correctly - and correct me if I am wrong - you have a textbox beside the checkbox to describe what the checkbox is for.
and the description with each checkbox they also want to change based on the date, so i use a text box but not allow user to enter infor
If this is what you are doing, this is not good design. Textboxes ARE for input. If you want to display text, then display text. Why are you using a textbox to display text, if the user can not enter etext inot. Yes, I know you can lock text in a textbox, and yes, there are some circumstances where this is good design. I fail to see why it would be here.

Why not just have text explaining the checkbox beside the checkbox? I may be missing something here.
do you know how to add the check box next to a text formfield?
Yes. Use the Formfields.Add method.

Gerry
My paintings and sculpture
 

--------------------------------
Why not just have text explaining the checkbox beside the checkbox? I may be missing something here.
---------------------------------

Gerry,

I am not very good at designing Work template. this is the one i am taking over from someone else. you are right that the reason I am using a text formfield next to the checkbox is to display text. i didn't see any property of a checkbox like in VB to describe what checkbox it is. Since users want to change the text of each checkbox based on the date they entered, so i used text formfiled. then i can find each text fieds to change to different description. are there any way to do this?

Use the Formfields.Add method.

i am trying to delete the checkbox, then add it back when date changed. but this template has tables, users can add or delete table. and the checkboxes are in each table. is i use the add method, i need to give a start and end range. it will very hard for me since it changing all the time.

 
It is true that formfield checkboxes do not have text with them. However, ActiveX checkboxes DO.
Since users want to change the text of each checkbox based on the date they entered
I am not getting this. A checkbox is used to check things. It is either checked, or not checked. The result, the consequences, of a check (or not check) may be all sorts of things. But are you really changing the text of the checkbox? No, you may be changing the text of a textbox - or something else.

OK, if you have the complication of the formfields being in tables, AND the users can delete the tables...then yeah....that would be complex to set up.

However, it certainly could be done. After all, the whole issue is still one of logic. It is just a bunch of logic statements really.

IF the user has set it with THIS condition THEN
the document looks like this
ELSE (the user has NOT set it as THIS condition)
the document looks like this different way
END IF

Or, if it gets very complex, you could change it to Select Case type logic.

Select Case whatever it is you are basing things on
Case if it is this way
make the document like this
Case if it is this other way
make the document like this
Case if it is this even MORE different way
make the document like this
Case Else
give a message to user..."Huh?"
End Select

All that is nice to say of course...but, as you have inherited the document, I realize that you may not have design control over it.
is i use the add method, i need to give a start and end range.
Not quite accurate, as you do not need to specify the explicit Start and End Range integers. You can use Selection.Range.

So go to where you want to add the formfield (make sure you add the proper spaces if required) and do something like:
Code:
Sub AddFF()
ActiveDocument.FormFields.Add Range:=Selection.Range, _
      Type:=wdFieldFormCheckBox
Selection.MoveLeft unit:=wdCharacter, Count:=1
With Selection.FormFields(1)
   .Name = "Bob"
   .ExitMacro = "TestMe"
End With
End Sub
I put the other stuff in to demonstrate that you can:

1. add the formfield at the selection point
2. back up the selection
3. set the attributes/properties of the new formfield

In this case I explicitly named the checkbox formfield "Bob", and made it fire the procedure "TestMe" when it is exited.

It seems that you are using some OnExit macros, so it may be important to be able to put those macros on a newly created formfield.

I strongly suggest that you always explicitly name your formfields (or ANY other control for that matter).

Also, it may be important (just in case) to .Collapse the Selection before you use it to make a formfield.

All in all though, my instincts tell me that this thing could probably be designed a bit better. Again, though, it it was handed to you, that may not be an option.

Gerry
My paintings and sculpture
 
Thank you so much for your reply and all the good suggestions. yes, i just can't redesign this template since they want to either show the new face or the old face just by changing one date field...

I did create 2 different templates for them and user can run a macro to open one template by the date they enter. But...

Thank you for all your help. really appreciate your time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top