#1
|
|||
|
|||
Dropdown dependencies with multiple dropdowns
I have used the content control code in https://www.msofficeforums.com/word-...own-lists.html successfully to allow users to select an item from a dropdown list located in the Header of a Word template. Thank you Macropod. The selected item then displays in a text box in the subsequent header. However I need to be able to interchange the headers (when the document is translated), with the new textbox displaying the new selection. The Headers inclusive of the Content Controls are saved as Quick Parts, that various editors will insert as they translate the document. Users may add any number of new Content Control Headers with the subsequent pages always needing to reflect the section's chosen dropdown item. How do I always refer to the next text box, and also ensure that the previous text boxes do not change? With thanks in advance.
|
#2
|
||||
|
||||
You could change the line:
Code:
ActiveDocument.ContentControls(2).Range.Text = StrDetails Code:
With ActiveDocument.SelectContentControlsByTitle("ClientDetails") .Item(.Count).Range.Text = StrDetails End With
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thank you Macropod
At the moment I have this: Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim i As Long, StrDetails As String With ContentControl If .Title = "CHOOSE SECTOR" 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 TextBoxLauren.Text = StrDetails ElseIf .Title = "CHOOSE SECTOR XHO" 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 TextBoxLauren.Text = StrDetails Else End If End With End Sub Last edited by macropod; 11-22-2017 at 01:05 AM. Reason: Added code tags |
#4
|
||||
|
||||
I see you code is writing to textboxes, via:
TextBoxLauren.Text = StrDetails Obviously, though, if you content controls are all using the same code, they'll all write to the same textbox. You need some way of differentiating the destinations. So, why are you writing to a textbox, and where is that textbox situated?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Hi Macropod. The word 'ECONOMICS' is the text box. I guess it doesn't necessarily need to be a text box but does need to show the name of the sector selected in the main heading. The textbox is within the header, and the headers all need to be available as Quick Parts
|
#6
|
|||
|
|||
I think I can simplify it like this. The template consists of
1. FRONT PAGE with a dropdown, the output of which needs to be reflected in the subsequent sub headers 2. COMPANY PAGE Quick Part Header with Dropdown, the output of which needs to be reflected in COMPANY PAGE Quick Part Sub Header Both the FRONT PAGE and subheader, and the company page header and related sub header Quick Parts need to be available in two languages, and insertable as many times as the user requires. |
#7
|
||||
|
||||
If your dropdown is in the header, you shouldn't need anything more than that, unless you're using a 'different first page' and/or 'different odd and even' page setup, as the dropdown selection will appear on all pages in that Section.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
I do have a different first page In the attached, the sub header on p4 is picking up the selection from the cover page, rather than from the page just before it 'INSERT COMPANY NAME'
|
#9
|
||||
|
||||
Try the following code. Do be careful, though, as it both deletes the content control title and converts the dropdown to a text content control as part of the 'locking' process you wanted. For the output, you'll need a text content control in whichever of the Section's headers you don't have the content control in. The code works equally well with or without a 'different first page' and/or 'different odd and even' page setup.
The other thing to be aware of is that, with content controls in the header, you need to click somewhere else in the header for the macro to run. Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean) Dim StrDetails As String, HdFt As HeaderFooter With CCtrl If .Title = "Sector" Then If .ShowingPlaceholderText = True Then Exit Sub .Title = "" StrDetails = .Range.Text .LockContentControl = False .Type = wdContentControlText For Each HdFt In .Range.Sections(1).Headers With HdFt If .Exists Then If .Range.ContentControls.Count = 1 Then With .Range.ContentControls(1) .LockContents = False .Range.Text = StrDetails .LockContents = True .LockContentControl = True End With End If End If End With Next End If End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
|||
|
|||
That works perfectly. Thank you SO much!
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Multiple entries in dropdown lists | paul_pearson | Word VBA | 151 | 10-18-2023 04:23 PM |
Multiple Selection Dropdown list | ajanson | Word VBA | 36 | 07-15-2019 08:16 PM |
Dropdown boxes to multiple fields? | Nukedaddy | Word | 3 | 09-16-2016 06:50 AM |
Content Control Dropdown Dependencies | asteinroeder | Word VBA | 5 | 10-28-2015 03:56 PM |
Multiple resource Dependencies / Mapping | Sherry | Project | 3 | 04-03-2014 08:03 AM |