Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2024, 06:43 AM
ccamm ccamm is offline Toggling control checkboxes to true when a value in a control drop down is selected Windows 10 Toggling control checkboxes to true when a value in a control drop down is selected Office 2021
Novice
Toggling control checkboxes to true when a value in a control drop down is selected
 
Join Date: Mar 2024
Posts: 2
ccamm is on a distinguished road
Default Toggling control checkboxes to true when a value in a control drop down is selected

I'm assuming this is a simple one, but its one of those days where I am banging my head against the wall. I'm more used to building stuff in power apps, and it spoon feeding me a lot of things so I am not as familiar with the VBA in words and what the items are called and I have available

right so what I am trying to do is this.

I have a named Dropdown control called ROLE, within it there are 4 options a user can select.

lets call them



a,b,c,d

and dependant on which one they select i want it to toggle a number (8) of check boxes on or off. Its not a simple if a then cb1 & 2 are set to true, as some of the check boxes will be true for more than one of the drop down option.

Im assuming I need to run it as an If/else similar to this


Code:
 If ddbox.ROLE.title = "a" Then 
 cb1 = "True"
 cb2 = "True"
 Cb4= "True" 
 ElseIf ddbox.ROLE.title = "b" Then 
 cb1 = "True"
 cb4 = "True"
 Cb5= "True"
 ElseIf ddbox.ROLE.title = "c" Then 
  cb2 = "True"
  cb3 = "True"
  cb4= "True"
  cb6= "True"
  cb8= "True"
 ElseIf ddbox.ROL.title = "d" Then 
  cb2 = "True"

 End If 
End Function
help please?
Reply With Quote
  #2  
Old 03-14-2024, 08:33 AM
ccamm ccamm is offline Toggling control checkboxes to true when a value in a control drop down is selected Windows 10 Toggling control checkboxes to true when a value in a control drop down is selected Office 2021
Novice
Toggling control checkboxes to true when a value in a control drop down is selected
 
Join Date: Mar 2024
Posts: 2
ccamm is on a distinguished road
Default

I have made some progress with this by using case rather than if else as it is a bit cleaner

Code:
Option Explicit

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    If ContentControl.Type = wdContentControlDropdownList Then
        If ContentControl.Title = "ROLE" Then 
            ChangeCheckBoxes ContentControl
        End If
    End If
End Sub

Sub ChangeCheckBoxes(ByRef dropdownControl As ContentControl)
    Dim dropdownValue As String
    dropdownValue = dropdownControl.Range.Text
    

    Select Case dropdownValue

        Case "RSC"
            ActiveDocument.SelectContentControlsByTitle("RPT").Item(1).Checked = True
            ActiveDocument.SelectContentControlsByTitle("DS").Item(1).Checked = True
  
            
        Case "LSC" 
   
            ActiveDocument.SelectContentControlsByTitle("DS").Item(1).Checked = True
            ActiveDocument.SelectContentControlsByTitle("SPT").Item(1).Checked = True
     
            
           
                
    End Select
End Sub
I think this should work and I should be able to add onto it, however Its not triggering
Reply With Quote
  #3  
Old 03-15-2024, 08:36 AM
gmaxey gmaxey is offline Toggling control checkboxes to true when a value in a control drop down is selected Windows 10 Toggling control checkboxes to true when a value in a control drop down is selected Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Your code seems to work fine here. Not to poke you in the eye with the obvious, but unfortunately the "trigger" is the act of exiting the content control. Therein lines the continuing stupidity of Microsoft (after over 15 years) of not have a content control "change" event.




Fortunately with Dropdowns, there is a "pseudo" change event called the ContentControlBeforeContentUpdate event. You can use it and XML mapping to do what you want. Attaching a demo file, but here is the code:

Code:
Private Sub Document_ContentControlBeforeContentUpdate(ByVal ContentControl As ContentControl, Content As String)
Dim oCXP As CustomXMLPart
  Select Case ContentControl.Title
    Case "ROLE"
      Set oCXP = ContentControl.XMLMapping.CustomXMLPart
      oCXP.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:RPT[1]").Text = "false"
      oCXP.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:DS[1]").Text = "false"
      oCXP.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:SPT[1]").Text = "false"
      Select Case Content
        Case "A"
         oCXP.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:RPT[1]").Text = "true"
         oCXP.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:DS[1]").Text = "true"
        Case "B"
          oCXP.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:DS[1]").Text = "true"
          oCXP.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:SPT[1]").Text = "true"
        Case "C"
          oCXP.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:RPT[1]").Text = "true"
        Case "D"
          oCXP.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:SPT[1]").Text = "true"
      End Select
    Case Else
  End Select
End Sub
Attached Files
File Type: docm Dependent checkboxes.docm (38.7 KB, 0 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 03-15-2024, 06:13 PM
Guessed's Avatar
Guessed Guessed is offline Toggling control checkboxes to true when a value in a control drop down is selected Windows 10 Toggling control checkboxes to true when a value in a control drop down is selected Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
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

The other obvious gotcha is that the Document_ContentControlOnExit macro has to be placed in the ThisDocument module and not a regular VBA module.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 03-16-2024, 06:44 AM
gmaxey gmaxey is offline Toggling control checkboxes to true when a value in a control drop down is selected Windows 10 Toggling control checkboxes to true when a value in a control drop down is selected Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Thanks for the backup Andrew.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Tags
checkbox, office365 desktop, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning Values to content control checkboxes and calculating results nuraish Word Tables 1 08-18-2021 03:14 AM
Using Content Control Checkboxes to open associated excel files shaztastic Word VBA 5 08-26-2018 07:13 AM
Toggling control checkboxes to true when a value in a control drop down is selected Content Control Checkboxes wlcdo2 Word VBA 3 01-05-2017 05:52 PM
Toggling control checkboxes to true when a value in a control drop down is selected Clicking the selected Content Control checkbox returns wrong control in vba event DougsGraphics Word VBA 2 06-24-2015 07:31 AM
Toggling control checkboxes to true when a value in a control drop down is selected Assigning Values to content control checkboxes and calculating results creative cathy Word Tables 13 10-07-2012 08:52 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:25 PM.


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