Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-28-2016, 05:29 PM
silverspr silverspr is offline Content Control values NOT display name Windows 8 Content Control values NOT display name Office 2010 64bit
Novice
Content Control values NOT display name
 
Join Date: Apr 2011
Posts: 24
silverspr is on a distinguished road
Default Content Control values NOT display name

HI


I have two content controls: CC1 and CC2 in separate tables
CC1 is a dropdown showing the display name:

Display name Value
meets 0.25
exceeds 0.75

I would like CC2 to show the value such that if CC1=meets, then CC2=0.25

I've tried the REF function and VBA to set the value but I can't get it to work, it seems the control created with ref takes the name of the control its referencing. Right now I'm exploring nested IF statements...these look messy!
any help is appreciated
thanks
Reply With Quote
  #2  
Old 05-28-2016, 09:51 PM
macropod's Avatar
macropod macropod is online now Content Control values NOT display name Windows 7 64bit Content Control values NOT display name Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

The simplest way is to use a ContentControlOnExit macro, coded along the lines of:
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Dim StrOut As String
With CCtrl
  If .Title = "CC1" Then
    If .Range.Text = "meets" Then
      StrOut = "0.25"
    Else
      StrOut = ""
    End If
    ActiveDocument.SelectContentControlsByTitle("CC2")(1).Range.Text = StrOut
  End If
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-29-2016, 08:18 AM
silverspr silverspr is offline Content Control values NOT display name Windows 8 Content Control values NOT display name Office 2010 64bit
Novice
Content Control values NOT display name
 
Join Date: Apr 2011
Posts: 24
silverspr is on a distinguished road
Default

Thank you for such a quick reply. I'm having difficulty, the code stops on:

ActiveDocument.SelectContentControlsByTitle("CC2") (1).Range.Text = StrOut

With the runtime error 438 object does not support this property or method.
Currently CC2 is a combo with no values? I've tried different CCtrls: rich text, plain text and dropbox, none have worked.

What content control should I be using?

thanks again
Reply With Quote
  #4  
Old 05-29-2016, 03:18 PM
macropod's Avatar
macropod macropod is online now Content Control values NOT display name Windows 7 64bit Content Control values NOT display name Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Your CC2 should be a text content control or a rich text content control - both of which support the code I posted.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 09-29-2020, 06:39 AM
Charles Kenyon Charles Kenyon is offline Content Control values NOT display name Windows 10 Content Control values NOT display name Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Late to the party, but this thread shows up in Google searches. I thought to add another method.

Code:
Sub DropDownValue()
    ' A scratch macro by Charles Kenyon  29 Sept 2020
    ' Assigns value of a DropDown Content Control to a string and reports in message box
    ' https://answers.microsoft.com/en-us/msoffice/forum/all/use-value-not-display-name-of-dropdown-menu-in-vba/0126575d-afa8-457e-aae7-693789f0ba2a
    '
    Dim ccMyCC As ContentControl
    Dim objLe As ContentControlListEntry
    Dim strText As String
    Dim strValue As String
    Set ccMyCC = ActiveDocument.ContentControls(1)
    Let strText = ccMyCC.range.Text
    For Each objLe In ccMyCC.DropdownListEntries
        If objLe.Text = strText Then Let strValue = objLe.Value
    Next
    MsgBox "The value associated with " & strText & " is " & strValue
    Set objLe = Nothing
    Set ccMyCC = Nothing
End Sub
Reply With Quote
  #6  
Old 09-29-2020, 07:08 AM
gmaxey gmaxey is offline Content Control values NOT display name Windows 10 Content Control values NOT display name Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
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

Lets say the CCs are Titled/Tagged "Condition" and "Value." The "Condition" CC is a dropdown with the display entries "meets" and "exceeds" with the values 0.25 and 0.75. The "Value" CC is a plain text CC.


If you mapped the to CCs to a CustomXMLPart to nodes named "Condition" and "Value" then you could use:

Code:
Private Sub Document_ContentControlBeforeStoreUpdate(ByVal ContentControl As ContentControl, Content As String)
  Select Case ContentControl.Tag
    Case "Condition"
      ContentControl.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:Value[1]").Text = Content
  End Select
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 09-29-2020, 02:49 PM
Charles Kenyon Charles Kenyon is offline Content Control values NOT display name Windows 10 Content Control values NOT display name Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

And, based on Paul's response to another question, here is a function:


Code:
Function CCValue(ccMyContentControl As ContentControl) As String
    ' Charles Kenyon 29 September 2020
    '
    ' Function based on Paul Edstein's Code
    ' https://stackoverflow.com/questions/58809271/how-to-get-dropdown-value-not-display-text-from-word-content-control-using-vba
    '
    If ccMyContentControl.Type <> wdContentControlDropdownList Then
        If ccMyContentControl.Type <> wdContentControlComboBox Then
            CCValue = ccMyContentControl.range.Text
            Exit Function
        End If
    End If
    Dim i As Long
    With ccMyContentControl
        For i = 1 To .DropdownListEntries.Count
            If .DropdownListEntries(i).Text = .range.Text Then _
                CCValue = .DropdownListEntries(i).Value
        Next i
    End With
End Function
Reply With Quote
  #8  
Old 09-29-2020, 03:09 PM
gmaxey gmaxey is offline Content Control values NOT display name Windows 10 Content Control values NOT display name Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
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

Charles,


Again, if the CCs are mapped it is a simple matter of:

Code:
Private Sub Document_ContentControlBeforeStoreUpdate(ByVal ContentControl As ContentControl, Content As String)
  Select Case ContentControl.Type
    Case 3, 4: Msgbox Content
  End Select
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #9  
Old 09-29-2020, 08:36 PM
Charles Kenyon Charles Kenyon is offline Content Control values NOT display name Windows 10 Content Control values NOT display name Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by gmaxey View Post
Charles,

Again, if the CCs are mapped it is a simple matter of:

***
Hi Greg,

I agree and your method is elegant.

Unfortunately most are not mapped and many of the people on these forums seem to be unwilling to try, even with the tools you provide. I map about a third of mine using your tools.
Reply With Quote
  #10  
Old 09-30-2020, 07:53 AM
gmaxey gmaxey is offline Content Control values NOT display name Windows 10 Content Control values NOT display name Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
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

Charles,


I agree that most people don't map. Then again, most people using CCs don't need the "Value" of the selected item either. Most people don't even know the difference between the display text and the value (i.e., the display is what is shown in the document, the value is what is stored in the CustomXMLPart (when mapped).


Certainly not trying to knock the function you provided. Just pointing out the benefits of mapping CCs.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Tags
content control, value not display name

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Content Control values NOT display name Code to Sum Column of Content Control Values In Specific Tables? warbird Word VBA 2 07-13-2015 05:44 AM
Word drop-down content control dependent display issue vvcat Word 6 02-03-2015 11:20 PM
how to make building block content control determine bb to display elsewhere jamles12 Word VBA 5 11-16-2013 11:38 AM
Content Control values NOT display name Content control merge values? skrallemand Word VBA 8 10-02-2013 06:54 AM
Content Control values NOT display name Assigning Values to content control checkboxes and calculating results creative cathy Word Tables 13 10-07-2012 08:52 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:41 AM.


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