WD: How to Create Mutually Exclusive Check Boxes Using WordBasic

ID: Q141081


The information in this article applies to:
  • Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows NT, version 6.0
  • Microsoft Word for the Macintosh, versions 6.0, 6.0.1
  • Microsoft Word for Windows 95, version 7.0


SUMMARY

This article explains how to create a macro for Form documents that will clear one check box if another check box is selected.

For example, you can use this macro if the form has one check box for True and one for False, and you want the user to select the True check box or the False check box, but not both. After this macro is assigned to both check boxes, the user can place an X in either the True or False box, and when the user clicks in another part of the form, the macro will remove the X from the other check box.

Another example is a series of check boxes where it is appropriate for the user to select only one option. For example: Mrs./Ms./Miss/Mr.


MORE INFORMATION

To turn an option off when a mutually exclusive counterpart is turned on (that is, toggle the other check box), create an On Exit macro for each check box form field.

The following macro toggles a check box off if its counterpart is selected. You must create one macro for each check box, changing the IF statement to check if the specific check box is selected and then clearing all other check boxes.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.


   Sub MAIN
      ' The following two lines retrieve the results of two check boxes.
      ' "check1" is the bookmark name of the check box and must be in
      ' quotation marks.
      check1 = GetFormResult("check1")
      check2 = GetFormResult("check2")
      ' The if statement checks to see if check box 1 is checked.
      ' If it is, it sets the second box to be unchecked.
      If check1 = 1 Then
         SetFormResult "check2", 0
      EndIf
   End Sub 


REFERENCES

"Microsoft Word Developer's Kit, Second Edition," pages 523, 524, 702, and 703

Additional query words: switch box checkbox

Keywords : kbui kbmacroexample winword macword word6 word7 word95
Version : WINDOWS:6.0,6.0a,6.0c,7.0,7.0a; MACINTOSH:6.0,6.0.1,6.0.1a
Platform : MACINTOSH Win95 WINDOWS winnt
Issue type : kbhowto


Last Reviewed: December 16, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.