#1
|
|||
|
|||
Content Controls - Multiple Drop Downs - VBA
Basically I have 2 Fields of which I want to have a drop down for with unique data the below code works perfectly for my Project manager section, but then when I want to run it against the engineer section it won't fill in the Engineer details section...I'm assuming there is some sort of join or piece of code I'm missing to get multiple drop downs utilizing the below code to act independent of each other.
I attached a screen shot of which may help show what I'm trying to do... HTML Code:
Option Explicit Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim i As Long, StrDetails As String With ContentControl If .tag = "ProjectManager" Then For i = 1 To .DropdownListEntries.Count If .DropdownListEntries(i).Text = .Range.Text Then StrDetails = Replace(.DropdownListEntries(i).Value, "|", Chr(11)) Exit For End If Next ActiveDocument.ContentControls(2).Range.Text = StrDetails End If End With End Sub HTML Code:
Option Explicit Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim i As Long, StrDetails As String With ContentControl If .tag = "Engineer" Then For i = 1 To .DropdownListEntries.Count If .DropdownListEntries(i).Text = .Range.Text Then StrDetails = Replace(.DropdownListEntries(i).Value, "|", Chr(11)) Exit For End If Next ActiveDocument.ContentControls(2).Range.Text = StrDetails End If End With |
#2
|
||||
|
||||
You can use case statements to identify the control and process accordingly. Note that both your examples populate contentcontrols(2), which seems improbable. Call the controls to be populated by their tags e.g. as follows.
You may find https://www.gmayor.com/insert_content_control_addin.htm useful Code:
Option Explicit Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim i As Long Dim strDetails As String Dim oCC As ContentControl With ContentControl If .ShowingPlaceholderText = False Then Select Case .Tag Case Is = "ProjectManager" For i = 1 To .DropdownListEntries.Count If .DropdownListEntries(i).Text = .Range.Text Then strDetails = Replace(.DropdownListEntries(i).Value, "|", Chr(11)) Exit For End If Next i Set oCC = ActiveDocument.SelectContentControlsByTag("Tag of the project manager details").Item(1) oCC.Range.Text = strDetails Case Is = "Engineer" For i = 1 To .DropdownListEntries.Count If .DropdownListEntries(i).Text = .Range.Text Then strDetails = Replace(.DropdownListEntries(i).Value, "|", Chr(11)) Exit For End If Next i Set oCC = ActiveDocument.SelectContentControlsByTag("Tag of the engineer details").Item(1) oCC.Range.Text = strDetails Case Else End Select End If End With Set oCC = Nothing End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
I'll give this a try tonight....my brain was fried and I haven't coded in 15 years lol
|
Tags |
content controls, drop down list, word 2019 |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Cascading drop-downs in Word with one parent menu and four dependent drop-downs | mrstrawhand | Word VBA | 3 | 03-30-2020 06:08 AM |
Populating multiple Content Controls after mail merge | guiltyvictim | Word VBA | 3 | 07-30-2019 09:27 AM |
Content Controls (Drop Down copy and paste), and XML mapping | dezdelaina | Word | 3 | 03-05-2018 06:50 PM |
2 drop down list content controls | danfookes | Word VBA | 2 | 03-02-2018 02:05 AM |
Inserting multiple content controls for a date | jeffreybrown | Word | 2 | 05-09-2016 05:53 PM |