Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-30-2013, 01:34 PM
skrallemand skrallemand is offline Content control merge values? Windows 7 64bit Content control merge values? Office 2007
Novice
Content control merge values?
 
Join Date: Aug 2013
Posts: 9
skrallemand is on a distinguished road
Default Content control merge values?


Hi

Great forum by the way

I want to use the values of 4 content control drop downs, and put them together in one textbox content control?

Example:

Dropdown 1 value = a
Dropdown 2 value = b
Dropdown 3 value = c
Dropdown 4 value = d

Textbox showing a+b+c+d

I know vba and content controls, but I don't know this

Thanks
Reply With Quote
  #2  
Old 09-30-2013, 02:31 PM
macropod's Avatar
macropod macropod is offline Content control merge values? Windows 7 32bit Content control merge values? 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

Assuming the dropdown controls you mentioned are the only ones in the document and your text content control has the title 'Output', you could use code in the document's 'This Document' module like:
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim StrOutput As String, CtrlID As String
If ContentControl.Type <> wdContentControlDropdownList Then Exit Sub
For Each ContentControl In ContentControls
  If ContentControl.Type = wdContentControlDropdownList Then
    If ContentControl.Range.Text <> ContentControl.PlaceholderText Then
      StrOutput = StrOutput & ContentControl.Range.Text & "+"
    Else
      StrOutput = StrOutput & "N/A" & "+"
    End If
  End If
  If ContentControl.Title = "Output" Then CtrlID = ContentControl.ID
Next
StrOutput = Left(StrOutput, Len(StrOutput) - 1)
ContentControls(CtrlID).Range.Text = StrOutput
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 09-30-2013, 02:59 PM
skrallemand skrallemand is offline Content control merge values? Windows 7 64bit Content control merge values? Office 2007
Novice
Content control merge values?
 
Join Date: Aug 2013
Posts: 9
skrallemand is on a distinguished road
Default

Thanks for the answer

Unfortunately, there are also other dropdown lists in the document, can the code be rewritten to work with the tags or titles?
Reply With Quote
  #4  
Old 09-30-2013, 03:03 PM
macropod's Avatar
macropod macropod is offline Content control merge values? Windows 7 32bit Content control merge values? 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 that may not be necessary. If, for example, you inserted a Section break each side of the set of dropdowns, you could code the macro to examine the controls in only that Section. That would allow you to add/delete dropdowns in the Section at a later date without a code re-write.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 09-30-2013, 03:54 PM
skrallemand skrallemand is offline Content control merge values? Windows 7 64bit Content control merge values? Office 2007
Novice
Content control merge values?
 
Join Date: Aug 2013
Posts: 9
skrallemand is on a distinguished road
Default

Then will the 'Output' content control box be located in another section. I feel more comfortable to be able to use tags or titles. If you may know a easy solution to use tags or titles, I would greatly appreciate it?

Anyway I'll try to work with the script you were so kind enough to give me.
Reply With Quote
  #6  
Old 09-30-2013, 04:01 PM
macropod's Avatar
macropod macropod is offline Content control merge values? Windows 7 32bit Content control merge values? 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

If you give all the input dropdowns the title 'Input', you could use:
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim StrOutput As String, CtrlID As String
If ContentControl.Type <> wdContentControlDropdownList Then Exit Sub
For Each ContentControl In ContentControls
  If ContentControl.Type = wdContentControlDropdownList Then
    If ContentControl.Title = "Input" Then
      If ContentControl.Range.Text <> ContentControl.PlaceholderText Then
        StrOutput = StrOutput & ContentControl.Range.Text & "+"
      Else
        StrOutput = StrOutput & "N/A" & "+"
      End If
    End If
  End If
  If ContentControl.Title = "Output" Then CtrlID = ContentControl.ID
Next
StrOutput = Left(StrOutput, Len(StrOutput) - 1)
ContentControls(CtrlID).Range.Text = StrOutput
End Sub
If they all have different titles, you'll need to add a series of OR tests to the 'If ContentControl.Title = "Input" Then' line.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 10-01-2013, 12:08 AM
skrallemand skrallemand is offline Content control merge values? Windows 7 64bit Content control merge values? Office 2007
Novice
Content control merge values?
 
Join Date: Aug 2013
Posts: 9
skrallemand is on a distinguished road
Default

it works, but I notice that the result in the 'output' textbox, comes from the text in the "Display Name" column in the dropdowns, and not from the "Value" column?

I am bound to use customxmlpart to use the "Value" column?
Reply With Quote
  #8  
Old 10-01-2013, 12:28 AM
macropod's Avatar
macropod macropod is offline Content control merge values? Windows 7 32bit Content control merge values? 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

I don't see where you've previously mentioned that the 'Value' column has anything other than the Display Name (default).

Getting values can be problematic if two or more have the same display names, as there's no vba for directly querying the displayed name's index #. Accordingly, one has to loop through all of them and compare the display name each against each list entry. Subject to that caveat, try:
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim StrOutput As String, CtrlID As String, i As Long
If ContentControl.Type <> wdContentControlDropdownList Then Exit Sub
For Each ContentControl In ContentControls
  With ContentControl
    If .Type = wdContentControlDropdownList Then
      If .Title = "Input" Then
        If .Range.Text <> .PlaceholderText Then
          For i = 1 To .DropdownListEntries.Count
            If .DropdownListEntries(i) = .Range.Text Then
              StrOutput = StrOutput & .DropdownListEntries(i).Value & "+"
            End If
          Next
        Else
          StrOutput = StrOutput & "N/A" & "+"
        End If
      End If
    End If
    If .Title = "Output" Then CtrlID = .ID
  End With
Next
StrOutput = Left(StrOutput, Len(StrOutput) - 1)
ContentControls(CtrlID).Range.Text = StrOutput
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 10-02-2013, 06:54 AM
gmaxey gmaxey is offline Content control merge values? Windows 7 32bit Content control merge values? Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
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

If you "Input" CCs are mapped and all tagged "Input" then you could use something like this:

Code:
Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
Dim strComposite As String
Dim oCC As ContentControl
  Select Case CC.Tag
    Case "Input"
      For Each oCC In ActiveDocument.ContentControls
        If oCC.Tag = "Input" Then
          If oCC.XMLMapping.IsMapped Then
            strComposite = strComposite & " " & oCC.XMLMapping.CustomXMLNode.Text
          End If
        End If
      Next oCC
      MsgBox strComposite
  Case Else
  
  End Select
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Content control merge values? Move to next content control cksm4 Word VBA 13 07-02-2019 07:48 PM
Content control merge values? Hierarchical content control ntjson Word VBA 1 04-04-2013 12:07 AM
Content control merge values? Content control titles jillapass Word VBA 3 05-29-2012 06:11 AM
Retrieving content control value jillapass Word VBA 4 05-24-2012 05:07 AM
Calendar control accepts other values JeJ Word 0 03-02-2011 03:38 PM

Other Forums: Access Forums

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