View Single Post
 
Old 08-19-2023, 03:11 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

It would be a start if you didn't have multiple checkboxes each named Checkbox1 or Checkbox2. They need to be uniquely named for the type of code event you are planning to work.
Then you will need to adjust your main code if you want the other checkbox pairs to work in a similar fashion.

Your checkbox entered is in the wrong Case selection group. It should be in the main group relating to CC

Code:
    Case "Checkbox1"
        If CC.Checked = True Then
            ActiveDocument.SelectContentControlsByTitle("Checkbox2").Item(1).Checked = False
            ActiveDocument.CustomDocumentProperties("Chk1").Value = 1
            ActiveDocument.CustomDocumentProperties("Chk2").Value = 0
        Else
            ActiveDocument.SelectContentControlsByTitle("Checkbox2").Item(1).Checked = True
            ActiveDocument.CustomDocumentProperties("Chk1").Value = 0
            ActiveDocument.CustomDocumentProperties("Chk2").Value = 1
        End If
        ActiveDocument.Fields.Update
    Case "Checkbox2"
        If CC.Checked = True Then
            ActiveDocument.SelectContentControlsByTitle("Checkbox1").Item(1).Checked = False
            ActiveDocument.CustomDocumentProperties("Chk2").Value = 1
            ActiveDocument.CustomDocumentProperties("Chk1").Value = 0
        Else
            ActiveDocument.SelectContentControlsByTitle("Checkbox1").Item(1).Checked = True
            ActiveDocument.CustomDocumentProperties("Chk2").Value = 0
            ActiveDocument.CustomDocumentProperties("Chk1").Value = 1
        End If
        ActiveDocument.Fields.Update
  End Select
End Sub
You also have assorted controls without titles/tags. I would recommend that each control is uniquely titled. It makes things much easier when trying to program events.
You may find Insert Content Control Add-In useful as a means of editing the controls (including the list box to remove the unwanted placeholder text).
Note that you don't need the module relating to Word 2007 compatibility. Word 2007 is not compatible with check box content controls, that were introduced with Word 2010.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com

Last edited by gmayor; 08-19-2023 at 10:59 PM.
Reply With Quote