View Single Post
 
Old 09-04-2015, 05:35 PM
Guessed's Avatar
Guessed Guessed is offline Windows 7 32bit Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You can have them both running easily enough.
Code:
Option Explicit

Sub ExclusiveCheckBoxes()
Dim strTemp As String
Dim oFF As FormField
Dim strGrpID As String
Dim strSeqID As String
Dim i As Long
Dim strSeqNext As String
  strTemp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 'Permits up to 26 checkboxes per group
  Set oFF = Selection.FormFields(1)
  If oFF.CheckBox.Value = True Then
    strGrpID = Left(oFF.Name, 8)
    strSeqID = UCase(Right(oFF.Name, 1))
  If strSeqID Like "[A-Z]" Then
    'Clear all GroupID ChkBoxes including the CB selected (ensure only one CB in group is selected).
    For i = 1 To Len(strTemp)
      strSeqNext = strGrpID & "_" & Mid(strTemp, i, 1)
      If ActiveDocument.Bookmarks.Exists(strSeqNext) Then
        ActiveDocument.FormFields(strSeqNext).CheckBox.Value = False
      End If
    Next i
    'Set the CB that was selected
    oFF.CheckBox.Value = True
    End If
  End If
  SetCheck
lbl_Exit:
  Exit Sub
End Sub
Sub SetCheck()
  Dim bChecked As Boolean
  bChecked = False
  With ActiveDocument
    If .FormFields("CHK_1234_A").CheckBox.Value Then bChecked = True
    If .FormFields("CHK_2345_A").CheckBox.Value Then bChecked = True
    If Not .FormFields("Check1").CheckBox.Value Then
      .FormFields("Check1").CheckBox.Value = bChecked
    End If
  End With
End Sub
You can avoid the need for code to set exclusivity if you use option form controls with a group setting. This is a different look to the box with an x in it though so perhaps you intentionally did it that way.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote