Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2005

Tip: Looking for answers? Try searching our database.

Linking check boxes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dawn Rhoads - 28 Apr 2005 19:42 GMT
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!
Jay Freedman - 28 Apr 2005 22:01 GMT
> 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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.