Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-05-2020, 01:36 AM
probinson76 probinson76 is offline Absolute Dependent Dropdown lists Windows 10 Absolute Dependent Dropdown lists Office 2016
Novice
Absolute Dependent Dropdown lists
 
Join Date: Jun 2020
Posts: 2
probinson76 is on a distinguished road
Default Absolute Dependent Dropdown lists

Using content controls, is it possible to create a dropdown that only appears, or becomes live, after a given response to a previous dropdown? For example, if a form filler responds with a yes, then another content control opens with a list of options, but if they respond with a no, the second dropdown doesn't appear or remains inaccessible? If so, how?
Reply With Quote
  #2  
Old 06-05-2020, 07:06 AM
macropod's Avatar
macropod macropod is offline Absolute Dependent Dropdown lists Windows 7 64bit Absolute Dependent Dropdown lists Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Yes, but (aside from the extra code that would be required) the problem with that is in telling Word where the new content control should go. One might use bookmarks, but those are all too easily deleted, expanded or moved by users who don't recognise their presence.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-06-2020, 07:17 AM
gmaxey gmaxey is offline Absolute Dependent Dropdown lists Windows 10 Absolute Dependent Dropdown lists Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
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

You can actually make this relatively robust (if complicated) by mapping some CCs to a customXMLPart and playing a shell game with the node text:


In the attached I created a master Yes/No "Question" DDL, a rich text "Container" CC, a temporary Rich Text CC containing a dependent DDL and mapped them to a customXML part. I then added a null node to the CXP. Then I deleted the temporary rich text CC and dependent DDL.



Code:
Option Explicit
Dim WithEvents oCXPart As CustomXMLPart
Sub AutoOpen()
On Error Resume Next
  Set oCXPart = ActiveDocument.CustomXMLParts.SelectByNamespace("http://TheAnchorage.com/XMLPart").Item(1)
lbl_Exit:
  Exit Sub
End Sub
Private Sub oCXPart_NodeAfterDelete(ByVal OldNode As Office.CustomXMLNode, ByVal OldParentNode As Office.CustomXMLNode, ByVal OldNextSibling As Office.CustomXMLNode, ByVal InUndoRedo As Boolean)
  'This event fires when a #text node containing a value is replaced with Null value.
  If OldParentNode.BaseName = "Question" Then ProcessChange OldNode, True
lbl_Exit:
  Exit Sub
End Sub
Private Sub oCXPart_NodeAfterInsert(ByVal NewNode As Office.CustomXMLNode, ByVal InUndoRedo As Boolean)
  'This event fires when the Null value in a CXPart element node is replaced with a #text node containing a value.
  ProcessChange NewNode
lbl_Exit:
  Exit Sub
End Sub
Private Sub oCXPart_NodeAfterReplace(ByVal OldNode As Office.CustomXMLNode, ByVal NewNode As Office.CustomXMLNode, ByVal InUndoRedo As Boolean)
  'This event fires when the initial Null value in the node is replaced with a value.
  ProcessChange NewNode
lbl_Exit:
  Exit Sub
End Sub
Sub ProcessChange(oNodePassed As Office.CustomXMLNode, Optional bDeadNode As Boolean = False)
Dim oNode As CustomXMLNode
Dim oCC As ContentControl
  If bDeadNode Then
    oCXPart.DocumentElement.ChildNodes(4).Text = oCXPart.DocumentElement.ChildNodes(3).Text
  Else
    If oNodePassed.ParentNode.BaseName = "Question" Then
      Select Case oNodePassed.Text
        Case Is = "Yes"
          oCXPart.DocumentElement.ChildNodes(4).Text = oCXPart.DocumentElement.ChildNodes(2).Text
        Case Else
          oCXPart.DocumentElement.ChildNodes(4).Text = oCXPart.DocumentElement.ChildNodes(3).Text
      End Select
    End If
  End If
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 06-06-2020, 06:54 PM
macropod's Avatar
macropod macropod is offline Absolute Dependent Dropdown lists Windows 7 64bit Absolute Dependent Dropdown lists Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Interesting, but the container remains in the document. I'm not sure what advantage that has over simply having a dependent dropdown control whose 'empty' placeholder text consists of, say, a 0-width space.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 06-07-2020, 07:50 AM
gmaxey gmaxey is offline Absolute Dependent Dropdown lists Windows 10 Absolute Dependent Dropdown lists Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
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

Paul, how is the container remaining in the document anymore egregious than leaving a bookmark in the document? The idea is to leverage the customXMLPart and its events. However, I take your point, it is over complicated to nest a DDL in a rich text CC.

As a demonstration of concept, I've modified the attached to add a plain text and DDL which is dependent on a master DDL selection.


Code:
Option Explicit
Dim WithEvents oCXPart As CustomXMLPart
Sub AutoOpen()
On Error Resume Next
  Set oCXPart = ActiveDocument.CustomXMLParts.SelectByNamespace("http://TheAnchorage.com/XMLPart").Item(1)
lbl_Exit:
  Exit Sub
End Sub
Private Sub oCXPart_NodeAfterDelete(ByVal OldNode As Office.CustomXMLNode, ByVal OldParentNode As Office.CustomXMLNode, ByVal OldNextSibling As Office.CustomXMLNode, ByVal InUndoRedo As Boolean)
  'This event fires when a #text node containing a value is replaced with Null value.
  If OldParentNode.BaseName = "Question" Then ProcessChange OldNode, True
lbl_Exit:
  Exit Sub
End Sub
Private Sub oCXPart_NodeAfterInsert(ByVal NewNode As Office.CustomXMLNode, ByVal InUndoRedo As Boolean)
  'This event fires when the Null value in a CXPart element node is replaced with a #text node containing a value.
  ProcessChange NewNode
lbl_Exit:
  Exit Sub
End Sub
Private Sub oCXPart_NodeAfterReplace(ByVal OldNode As Office.CustomXMLNode, ByVal NewNode As Office.CustomXMLNode, ByVal InUndoRedo As Boolean)
  'This event fires when the initial Null value in the node is replaced with a value.
  ProcessChange NewNode
lbl_Exit:
  Exit Sub
End Sub
Sub ProcessChange(oNodePassed As Office.CustomXMLNode, Optional bDeadNode As Boolean = False)
Dim oNode As CustomXMLNode
Dim oCC_DDL As ContentControl, oCC_PT As ContentControl
  Set oCC_DDL = ActiveDocument.SelectContentControlsByTag("DepDDL").Item(1)
  Set oCC_PT = ActiveDocument.SelectContentControlsByTag("fixText").Item(1)
  If bDeadNode Then
    With oCC_DDL
      .LockContents = False
      .Type = 1
      .Range.Text = vbNullString
      .SetPlaceholderText , , ChrW(8203)
      .LockContents = True
    End With
     With oCC_PT
      .LockContents = False
      .Range.Text = vbNullString
      .LockContents = True
    End With
  Else
    If oNodePassed.ParentNode.BaseName = "Question" Then
      Select Case oNodePassed.Text
        Case Is = "Yes"
          With oCC_DDL
            .SetPlaceholderText , , "Choose item"
            .Type = 4
            .LockContents = False
            .Range.Select
          End With
          With oCC_PT
           .LockContents = False
           .Range.Text = "Please select from menu:"
           .LockContents = True
         End With
        Case Else
          With oCC_DDL
            .LockContents = False
            .Type = 1
            .Range.Text = vbNullString
            .SetPlaceholderText , , ChrW(8203)
            .LockContents = True
          End With
          With oCC_PT
           .LockContents = False
           .Range.Text = vbNullString
           .LockContents = True
         End With
      End Select
    End If
  End If
lbl_Exit:
  Exit Sub
End Sub
Attached Files
File Type: docm Linked text using CustomXMLPart events.docm (39.5 KB, 9 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #6  
Old 06-07-2020, 03:59 PM
macropod's Avatar
macropod macropod is offline Absolute Dependent Dropdown lists Windows 7 64bit Absolute Dependent Dropdown lists Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by gmaxey View Post
Paul, how is the container remaining in the document anymore egregious than leaving a bookmark in the document?
It isn't. What I likened it to was leaving a
Quote:
dependent dropdown control whose 'empty' placeholder text consists of, say, a 0-width space
for which the coding would be significantly simpler.

The real issue, though is whether anything more substantial than a bookmark should exist in the document when the dependent dropdown control isn't needed.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
#dropdown#dependent

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Absolute Dependent Dropdown lists Content Controls - Dependent Dropdown someazguy Word VBA 14 02-05-2023 08:01 PM
Absolute Dependent Dropdown lists Multiple dependent dropdown lists in table with add new row option jeweldarby Word VBA 6 05-21-2022 04:37 PM
Absolute Dependent Dropdown lists Dependent dropdown and repeat section NLJ Word VBA 3 01-12-2020 05:00 PM
Dropdown dependent text JakeLRL Word VBA 7 04-07-2016 08:26 AM
Dependent drop down lists bobbych Word 1 02-08-2013 04:38 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:09 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