WD97: Grouped Floating Option Buttons Not Mutually Exclusive

Last reviewed: August 27, 1997
Article ID: Q168851
The information in this article applies to:
  • Microsoft Word 97 for Windows

SYMPTOMS

When you group a series of ActiveX option buttons on a Microsoft Word document by setting the group name for each ActiveX option button to the same name, changing the value of one ActiveX option button within the group to TRUE does not toggle the values of the other ActiveX option buttons within the same group to FALSE.

CAUSE

By Design, ActiveX option buttons, when inserted from the Control Toolbox, are inserted as floating objects. Option buttons inserted as floating objects are not mutually exclusive, even when their GroupName property is identical.

WORKAROUND

To work around this problem, use one of the following methods.

Method 1: Convert the ActiveX Option Buttons to Inline Objects

Converting the ActiveX option buttons to inline objects will allow you to toggle the values of grouped option buttons.

To convert the ActiveX option buttons to inline objects:

  1. If the Control Toolbox is not visible, on the View menu, point to Toolbars, and click Control Toolbox.

  2. On the Control Toolbox, click Design Mode.

  3. Select an option button to convert to inline.

  4. Right-click the option button to display the option button shortcut menu.

  5. On the option button shortcut menu, point to OptionButton Object and click Convert.

  6. On the Convert dialog box, clear the Float Over Text check box.

  7. Click OK.

  8. Repeat steps 3-7 for each option button you want to group.

To group the option buttons:

  1. Select an option button to group.

  2. On the Control Toolbox, click Properties.

  3. In the GroupName property text box, type a unique group name for each option button within the same grouping.

    For example, if you have inserted four option buttons onto a document and you want to have two separate groups consisting of

          Group1: Option Buttons 1 and 2
          Group2: Option Buttons 3 and 4
    

    Type "Group1" (without the quotation marks), as the GroupName value for option buttons 1 and 2.

    Type "Group2" (without the quotation marks) as the GroupName value for option buttons 3 and 4.

  4. Repeat steps 1-3 for each option button within similar groupings.

Method 2: Use the Following Macro Examples to Toggle the Values

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

The following sample Visual Basic for Applications macro will allow you to keep the option button float over text status and toggle the values based on groupings.

Before running the macro examples, group the option buttons as detailed in the steps "To group the option buttons" described earlier in this article.

Place the following procedure in the General Declarations section of the Normal project.

   Public Sub SetOptionGroupValues(sName As Object)
      Dim sGroup As String
      Dim oShape As Shapes
      Set oShape = ActiveDocument.Shapes
      For i = 1 To oShape.Count
         ' If the Shape is an Option Button.
         If oShape(i).OLEFormat.ClassType = "Forms.OptionButton.1" Then
            ' If the Option Button in the collection
            ' is NOT the selected option button.
            If oShape(i).OLEFormat.Object.name <> sName.name Then
               ' If the option button is in the defined group.
               If oShape(i).OLEFormat.Object.GroupName = _
               sName.GroupName Then
                  ' Make it's value false.
                  oShape(i).OLEFormat.Object.Value = False
               End If
            End If
         End If
      Next
   End Sub

For each option button in your group, place the following example code that calls the SetOptionGroupValues sub-routine within each option button's GotFocus event procedure.

   SetOptionGroupValues <OptionButtonName>

The argument, <OptionButtonName> must match the name of the option button.

For example,

   Private Sub OptionButton1_GotFocus()
      SetOptionGroupValues OptionButton1
   End Sub

   Private Sub OptionButton2_GotFocus()
      SetOptionGroupValues OptionButton2
   End Sub

To view the GotFocus event procedure for an option button:

  1. In design mode, double-click an option button.

  2. In the Visual Basic for Applications Editor Code window, select GotFocus from the Procedures box.


Additional query words: word97 word8 8.0 8.0 vb vbe vba
Keywords : kbcode kbmacro kbprg kbtool PgmColl PgmHowTo kbmacroexample
Version : 97
Platform : WINDOWS
Issue type : kbhowto
Solution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 27, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.