Hi,

I have a work template which has 2 check box form fields. I try to hide one
of the check box depending on user enter information from a text field. is
this possible? How can do this.

And also, can I change a text formfield's backgroud color to different color?

Please help.

Re: Hide CheckBox FormField by Cindy

Cindy
Sat Sep 02 05:06:00 CDT 2006

Hi =?Utf-8?B?Qko=?=,

> I have a work template which has 2 check box form fields. I try to hide one
> of the check box depending on user enter information from a text field. is
> this possible? How can do this.
>
Yes, this should be possible. But please note that the change can only occur
when the user EXITS the "trigger" checkbox. Form fields' macros do not trigger
when you "click" or type in them, only when entering and exiting.

The following sample code hides the checkbox named Check1 if Check2 is
activated; if it's not, Check1 is not hidden.

Sub HideBox()
Dim doc As Word.Document
Dim chkToHide As Word.FormField
Dim chkTrigger As Word.CheckBox

Set doc = ActiveDocument
Set chkToHide = doc.FormFields("Check1")
Set chkTrigger = doc.FormFields("Check2").CheckBox
If doc.ProtectionType <> wdNoProtection Then _
doc.Unprotect
chkToHide.Range.Font.Hidden = chkTrigger.Value
doc.Protect wdAllowOnlyFormFields, True
End Sub

> And also, can I change a text formfield's backgroud color to different color?
>
Sure, just select it and use Format/Borders and Shading to add a shading to the
selection. But note that you must turn off the "field shading" (button with a
"a" on it in the Forms toolbar) for this to be visible.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)


Re: Hide CheckBox FormField by BJ

BJ
Tue Sep 05 08:46:01 CDT 2006

Hi Cindy,

Thank you so much. I will try it now.

one more question, is there a property of checkbox allow me to put a
description next to it like in VB?

Thanks.

"Cindy M." wrote:

> Hi =?Utf-8?B?Qko=?=,
>
> > I have a work template which has 2 check box form fields. I try to hide one
> > of the check box depending on user enter information from a text field. is
> > this possible? How can do this.
> >
> Yes, this should be possible. But please note that the change can only occur
> when the user EXITS the "trigger" checkbox. Form fields' macros do not trigger
> when you "click" or type in them, only when entering and exiting.
>
> The following sample code hides the checkbox named Check1 if Check2 is
> activated; if it's not, Check1 is not hidden.
>
> Sub HideBox()
> Dim doc As Word.Document
> Dim chkToHide As Word.FormField
> Dim chkTrigger As Word.CheckBox
>
> Set doc = ActiveDocument
> Set chkToHide = doc.FormFields("Check1")
> Set chkTrigger = doc.FormFields("Check2").CheckBox
> If doc.ProtectionType <> wdNoProtection Then _
> doc.Unprotect
> chkToHide.Range.Font.Hidden = chkTrigger.Value
> doc.Protect wdAllowOnlyFormFields, True
> End Sub
>
> > And also, can I change a text formfield's backgroud color to different color?
> >
> Sure, just select it and use Format/Borders and Shading to add a shading to the
> selection. But note that you must turn off the "field shading" (button with a
> "a" on it in the Forms toolbar) for this to be visible.
>
> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
> http://www.word.mvps.org
>
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)
>
>

Re: Hide CheckBox FormField by Cindy

Cindy
Wed Sep 06 07:55:32 CDT 2006

Hi =?Utf-8?B?Qko=?=,

> one more question, is there a property of checkbox allow me to put a
> description next to it like in VB?
>
No, form fields don't have such a property. You just type the text next
to the checkbox, in the document.

If your concern is hiding that, as well, I recommend you create a
Character Style. Then you can change the style definition to turn
hidden on/off. Actually, you can do that without even removing document
protection...

Sub ChangeHidden()
ActiveDocument.Styles("Check1").Font.Hidden _
= ActiveDocument.FormFields("check2").CheckBox.Value
End Sub


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)


Re: Hide CheckBox FormField by BJ

BJ
Wed Sep 06 09:41:01 CDT 2006

Cindy,

you are good!!!

Can i ask you one more question? sorry, it's a different topic.

Insteading of hiding the text typed next to the checkbox, i am trying to run
a macro to replace the existing text to different text. for example, replace
"Excellent" with "Good". but when i run this, if there are same word
"Excellent" user typed in a text formfield, it will be replaced also. how can
i only replace the "Excellent" next to the checkbox but not the one in text
formfield?

really appreciate your time.

"Cindy M." wrote:

> Hi =?Utf-8?B?Qko=?=,
>
> > one more question, is there a property of checkbox allow me to put a
> > description next to it like in VB?
> >
> No, form fields don't have such a property. You just type the text next
> to the checkbox, in the document.
>
> If your concern is hiding that, as well, I recommend you create a
> Character Style. Then you can change the style definition to turn
> hidden on/off. Actually, you can do that without even removing document
> protection...
>
> Sub ChangeHidden()
> ActiveDocument.Styles("Check1").Font.Hidden _
> = ActiveDocument.FormFields("check2").CheckBox.Value
> End Sub
>
>
> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
> http://www.word.mvps.org
>
> This reply is posted in the Newsgroup; please post any follow question
> or reply in the newsgroup and not by e-mail :-)
>
>

Re: Hide CheckBox FormField by Cindy

Cindy
Wed Sep 06 11:03:13 CDT 2006

Hi =?Utf-8?B?Qko=?=,

> Insteading of hiding the text typed next to the checkbox, i am trying to run
> a macro to replace the existing text to different text. for example, replace
> "Excellent" with "Good". but when i run this, if there are same word
> "Excellent" user typed in a text formfield, it will be replaced also. how can
> i only replace the "Excellent" next to the checkbox but not the one in text
> formfield?
>
Basically, you need to restrict the range you're acting on to what follows the
form field up to the end of the "caption". Since I don't know how you've
designed what you have, it's rather difficutl to provide an example... Assuming
checkbox and "caption" are in a Word paragraph, with nothing else, I'd approach
it along these lines

Sub ChangeHidden2()
Dim doc As Word.Document
Dim rngSearch As Word.Range
Dim ffld As Word.FormField

Set doc = ActiveDocument
Set ffld = doc.FormFields("check1")
Set rngSearch = ffld.Range.Paragraphs(1).Range
rngSearch.Start = ffld.Range.End
'TODO: Unprotect
rngSearch.Text = "Good"
'TODO: Reprotect
End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)


Re: Hide CheckBox FormField by BJ

BJ
Wed Sep 06 13:11:01 CDT 2006

Cindy,

I have 3 checkboxes on a line. and need to change all the text description
of them. the code you gave to me works perfectly for only one checkbox one
Paragraph.

Please help.

Thank you!!!

"Cindy M." wrote:

> Hi =?Utf-8?B?Qko=?=,
>
> > Insteading of hiding the text typed next to the checkbox, i am trying to run
> > a macro to replace the existing text to different text. for example, replace
> > "Excellent" with "Good". but when i run this, if there are same word
> > "Excellent" user typed in a text formfield, it will be replaced also. how can
> > i only replace the "Excellent" next to the checkbox but not the one in text
> > formfield?
> >
> Basically, you need to restrict the range you're acting on to what follows the
> form field up to the end of the "caption". Since I don't know how you've
> designed what you have, it's rather difficutl to provide an example... Assuming
> checkbox and "caption" are in a Word paragraph, with nothing else, I'd approach
> it along these lines
>
> Sub ChangeHidden2()
> Dim doc As Word.Document
> Dim rngSearch As Word.Range
> Dim ffld As Word.FormField
>
> Set doc = ActiveDocument
> Set ffld = doc.FormFields("check1")
> Set rngSearch = ffld.Range.Paragraphs(1).Range
> rngSearch.Start = ffld.Range.End
> 'TODO: Unprotect
> rngSearch.Text = "Good"
> 'TODO: Reprotect
> End Sub
>
> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
> http://www.word.mvps.org
>
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)
>
>

Re: Hide CheckBox FormField by Cindy

Cindy
Thu Sep 07 04:17:49 CDT 2006

Hi =?Utf-8?B?Qko=?=,

> I have 3 checkboxes on a line. and need to change all the text description
> of them. the code you gave to me works perfectly for only one checkbox one
> Paragraph.
>
That's pretty tricky... Can you put the three checkboxes in a table, one in
each table cell?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)


Re: Hide CheckBox FormField by BJ

BJ
Thu Sep 07 12:20:03 CDT 2006

Hi Cindy,

Basied on what you have given to me from the last post I have figured out
how to do it. The following is an example:

Set fldOut = doc.FormFields("ckGood" & intCk)
Set rngOut = fldOut.Range.Paragraphs(1).Range
rngOut.Start = fldOut.Range.End
rngOut.SetRange Start:=rngOut.Start + 1, End:=rngOut.Start + 20

rngGood.Text = " Good" & Space(15)

Thank you very much.


"Cindy M." wrote:

> Hi =?Utf-8?B?Qko=?=,
>
> > I have 3 checkboxes on a line. and need to change all the text description
> > of them. the code you gave to me works perfectly for only one checkbox one
> > Paragraph.
> >
> That's pretty tricky... Can you put the three checkboxes in a table, one in
> each table cell?
>
> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
> http://www.word.mvps.org
>
> This reply is posted in the Newsgroup; please post any follow question or
> reply in the newsgroup and not by e-mail :-)
>
>