WD: How to Create Mutually Exclusive Check Boxes Using WordBasic |
Q141081
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.
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
"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
Issue type : kbhowto
Technology : kbHWMAC kbOSMAC kbWordSearch kbWordMacSearch kbWord700Search kbZNotKeyword2 kbZNotKeyword3 kbWord600Mac kbWord601Mac kbWord600 kbWord600a kbWord600c kbWord700 kbWord600NT
|
Last Reviewed: November 5, 2000 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |