Linked Content Control

Hello,

I read this:

http://gregmaxey.mvps.org/word_tip_pages/linked_content_control_dropdown_list.html

But I need to use only Method 3, but the page only describes how to get the two dependent drop down lists. How can I get something like Method 3?

Is there another page? Or maybe just a set of other codes? I can't seem to filter it out of the long code in VBA.

Thank you very much!!!

Answer
Answer

There is an End Select and End Sub missing from the point shown by the red line in this screen shot of your code:

However, see the code posted below for the minimum code that you need for Method 3 to work.

The Food items, Food Groups\Colours are defined via the Content Control Properties dialog

You can replace the Display Names and Values with your own data, Before doing that however, I would suggest that you first try adding a new item and its associated Values.  Note the food group and the colour must be separated by a |.

The following is the code that you need for the 3rd method to work:

Dim i As Long
Private Type ListData
  strType As String
  strColor As String
  arrFood() As String
End Type
Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
Dim tData As ListData
  If Application.Version < "14.0" Then Main.SetDeveloperTabActive
  Select Case CC.Tag
    Case Is = "DD Demo 3"
      tData = GetDataIII(CC)
      With ActiveDocument
        With .SelectContentControlsByTitle("TypeIII").Item(1)
          .LockContents = False
          .Range.Text = tData.strType
          .LockContents = True
        End With
        With .SelectContentControlsByTitle("ColorIII").Item(1)
          .LockContents = False
          .Range.Text = tData.strColor
          .LockContents = True
        End With
      End With
  End Select
lbl_Exit:
  Exit Sub
End Sub
Private Function GetDataIII(ByRef oCCPassed) As ListData
Dim arrData() As String
  For i = 1 To oCCPassed.DropdownListEntries.Count
    If oCCPassed.Range.Text = oCCPassed.DropdownListEntries(i).Text Then
      arrData() = Split(oCCPassed.DropdownListEntries(i).Value, "|")
      Exit For
    End If
  Next i
  On Error GoTo Err_NoPick
  GetDataIII.strType = arrData(0)
  GetDataIII.strColor = arrData(1)
  Exit Function
Err_NoPick:
  GetDataIII.strType = ""
  GetDataIII.strColor = ""
lbl_Exit:
  Exit Function
End Function

If you change the tags of the Content Controls, you will need to make the same changes in the code

Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com
It's time to replace ‘Diversity, Equity & Inclusion’ with ‘Excellence, Opportunity & Civility’ - V Ramaswamy

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 310 Applies to: