I have a form with two lists of checkboxes. Some checkboxes from list A
should automatically choose a particular checkbox from list B. So, for
instance, if any one of checkboxes 1, 3, 5, or 7 is checked, then checkbox 10
should also be checked. Only one of 1, 3, 5, or 7 will be checked at any
one time, all others will be unchecked.
I found the following code in the newsgroups that will work for a making one
checkbox automatically check a second one. (Thanks!) This could work in my
situation, but I would have to use separate macros for each of my checkboxes.
I am wondering if there is a way to put all into one macro.
Sub SetCheckboxes()
ActiveDocument.FormFields("Check2").CheckBox.Value _
= ActiveDocument.FormFields("Check1").CheckBox.Value
End Sub
Thanks for any ideas anyone can give me!
> I have a form with two lists of checkboxes. Some checkboxes from
> list A should automatically choose a particular checkbox from list B.
[quoted text clipped - 14 lines]
>
> Thanks for any ideas anyone can give me!
Hi Dawn,
In the code you showed, the names "Check1" and "Check2" are literal strings
but you could use string variables instead. In particular, if the code is in
the exit macro of a checkbox form field, then the name of the form field the
user has just exited is given by
Selection.FormFields(1).Name
[Note that this doesn't work correctly for text form fields; if you need to
work with them, see
http://word.mvps.org/FAQs/TblsFldsFms/GetCurFmFldName.htm.]
So let's say this particular macro is going to be assigned as the exit macro
for Check1, Check3, Check5, and Check7 (but not the others). You can use
Sub SetCheckboxes()
ActiveDocument.FormFields("Check10").CheckBox.Value = _
ActiveDocument.FormFields( _
Selection.FormFields(1).Name).CheckBox.Value
End Sub
You may also be interested in the code at
http://word.mvps.org/FAQs/TblsFldsFms/ExclusiveFmFldChbxs.htm.

Signature
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Dawn Rhoads - 28 Apr 2005 22:56 GMT
Thanks Jay! This sort of worked for me, but here's what I found. As I
tabbed through each box, the macro would re-run and then pick up the value
(checked or unchecked) of the box I just tabbed out of and applied it to box
10. So, if I check box 1, box 10 would get checked. But as I tab through
the rest of my boxes, when I reach box 3 and pass by it without checking it,
box 10 would then uncheck.
It's LIKELY that users will use the mouse to check the boxes, in which case
this appears to be dandy, but still possible that they would tab through them
all. Any thoughts on getting around the tabbing? (I guess the route of
writing separate macros for boxes 1, 3, 5 and 7 would be one way around.)
Thanks again for your time!
> > I have a form with two lists of checkboxes. Some checkboxes from
> > list A should automatically choose a particular checkbox from list B.
[quoted text clipped - 39 lines]
> You may also be interested in the code at
> http://word.mvps.org/FAQs/TblsFldsFms/ExclusiveFmFldChbxs.htm.
Jay Freedman - 29 Apr 2005 02:00 GMT
Hi Dawn,
Yeah, sorry, a bad case of brain fade there...
What you really want is that any time any checkbox is exited, the
macro looks at all the "interesting" checkboxes to see if any of them
are checked. The way to do that is to use the Or logical operator to
combine the "interesting" checkbox Value preperties into one
true/false value. That looks like this:
Sub SetCheckboxes()
ActiveDocument.FormFields("Check10").CheckBox.Value = _
ActiveDocument.FormFields("Check1").CheckBox.Value Or _
ActiveDocument.FormFields("Check3").CheckBox.Value Or _
ActiveDocument.FormFields("Check5").CheckBox.Value Or _
ActiveDocument.FormFields("Check7").CheckBox.Value
End Sub
You can make this the exit macro for all the "interesting" checkboxes.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
>Thanks Jay! This sort of worked for me, but here's what I found. As I
>tabbed through each box, the macro would re-run and then pick up the value
[quoted text clipped - 53 lines]
>> You may also be interested in the code at
>> http://word.mvps.org/FAQs/TblsFldsFms/ExclusiveFmFldChbxs.htm.
Dawn Rhoads - 29 Apr 2005 17:16 GMT
That's the ticket! Works beautifully. Thanks so much for your help, I
really appreciate it!
> Hi Dawn,
>
[quoted text clipped - 78 lines]
> >> You may also be interested in the code at
> >> http://word.mvps.org/FAQs/TblsFldsFms/ExclusiveFmFldChbxs.htm.