Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-18-2023, 09:29 AM
kvrieze kvrieze is offline Use VBA to show text when content control check box is checked Windows 10 Use VBA to show text when content control check box is checked Office 2019
Novice
Use VBA to show text when content control check box is checked
 
Join Date: Feb 2020
Posts: 1
kvrieze is on a distinguished road
Default Use VBA to show text when content control check box is checked

I am trying to set a word document up, so that when the user checks a content control "Yes" check box, pre-defined text that asks a follow up question will appear below the original question. I used an example code I found online but when I insert the code into my document, it does not work. I have named the checkboxes, as they did in the example and have insert field code where the text should appear and also set up custom document properties, however, it still does not work. Can anyone provide some guidance on this? I have attached the file, so that you can see what I am referencing. It is on page 9 of the document, and I have highlighted the four areas I am referencing. If the user selects No, there is no text that appears. They will just proceed to the next question.
Attached Files
File Type: docm JCS Service Plan v5.1.docm (208.3 KB, 9 views)
Reply With Quote
  #2  
Old 08-19-2023, 03:11 AM
gmayor's Avatar
gmayor gmayor is offline Use VBA to show text when content control check box is checked Windows 10 Use VBA to show text when content control check box is checked Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
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 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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Use VBA to show text when content control check box is checked Check box content control to show text when checked Strogg Word 3 02-10-2019 11:45 AM
VBA in Word 2010 to show certain text only when a YES checkbox is checked kdsim Word VBA 0 05-16-2018 05:16 AM
Check Box Content Control when checked users are presented with an option cryder Word 0 01-07-2016 05:11 AM
how to show total of check boxes checked worder Word 16 03-10-2014 05:07 PM
Word2010 check boxes and plain text content control boxes in same table fcsungard Word 5 06-01-2012 01:16 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:41 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft