WD97: Grouped Floating Option Buttons Not Mutually Exclusive

ID: Q168851


The information in this article applies to:


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 inserted four option buttons in 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.


NOTE: To allow the text to wrap around the option buttons, place them in a frame (do not use a text box).

For additional information about using Frames, please see the following article in the Microsoft Knowledge Base:
Q159942 WD97: General Information about Text Boxes and Frames in Word 97

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



Microsoft provides programming examples 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. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/refguide/
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: wordcon word97 word8 8.0 vb vbe vba


Keywords          : kbcode kbmacro kbprg kbtool kbmacroexample 
Version           : WINDOWS:
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: June 23, 1999