Consulting

Results 1 to 4 of 4

Thread: Checking if a content control combo box value is a number between x and y

  1. #1
    VBAX Newbie
    Joined
    Jan 2014
    Posts
    2
    Location

    Checking if a content control combo box value is a number between x and y

    Hello,

    I am creating a test results template to report scores from a particular test. I have a table in word with content control combo boxes to type in the numerical score. It has to be a combo box because it is possible to obtain a score of "<100" so I have that value as an option in the drop down, but if it isn't that value, the user types in the numerical value.

    Below the table, I have a paragraph describing the test results. There is a sentence where it repeats the numerical value listed in the chart, but it also has a combo box that contains a list of the classification descriptions. For example, scores below 55 are considered "average", scores between 55 and 59 are considered "mildly elevated", scores between 60 and 69 are considered "moderately elevated", and scores 70 and above are considered "extremely elevated".

    So the sentence looks like this: "This individual obtained a score of [score combo box], which fell in the [classification combo box] range."

    I am trying to figure out how to code it so that I can have the classification populate based on the value in the combo box. So if I enter "72" in the score combo box, the classification combo box will show "extremely elevated" because the score combo box value was 70 or above.

    I hope that makes sense. I would greatly appreciate any help you could give me.

    Thanks.

  2. #2
    Odd that your scores don't have a 'below average' class? Apart from that the principles are straightforward enough and the text reproduced using bookmarks populated from the combobox. See attached. The principles can be extended to other dropdowns in the same document by adding more case statements to the macro as appropriate.

    When working with content controls, you should find https://www.gmayor.com/insert_content_control_addin.htm useful.
    Attached Files Attached Files
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Newbie
    Joined
    Jan 2014
    Posts
    2
    Location
    Quote Originally Posted by gmayor View Post
    Odd that your scores don't have a 'below average' class? Apart from that the principles are straightforward enough and the text reproduced using bookmarks populated from the combobox. See attached. The principles can be extended to other dropdowns in the same document by adding more case statements to the macro as appropriate.

    When working with content controls, you should find https://www.gmayor.com/insert_content_control_addin.htm useful.
    Graham,

    I really appreciate your time and response. Your suggestion worked perfectly. Thank you so much, you are the best!

    Just FYI, the scores don't have a "below average" classification because the test is a measure of a particular set of symptoms, so the only thing we are interested in is an abnormal (i.e. above average) score.

    Take care and have a great day! I'm sure I'll be around in the not so distant future to ask more questions.

    Thanks again.

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    Anarxo,

    As an alternative to the CC Exit event Graham shows, you can use the following event to do something similar:

    Private Sub Document_ContentControlBeforeContentUpdate(ByVal ContentControl As ContentControl, Content As String)
    Dim oCC As ContentControl
      Select Case ContentControl.Tag
        Case Is = "score combo box"
          Select Case Content
            Case Is = "Choose an item."
              ContentControl.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:classification_combo_box[1]").Text = ""
              Content = ""
            Case Is < 55
              ContentControl.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:classification_combo_box[1]").Text = "average"
            Case Is < 59
              ContentControl.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:classification_combo_box[1]").Text = "mildly elevated"
            Case Is < 69
              ContentControl.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:classification_combo_box[1]").Text = "moderately elevated"
            Case Else
              ContentControl.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:classification_combo_box[1]").Text = "extremely elevated"
          End Select
        Case Else
      End Select
    lbl_Exit:
      Exit Sub
    End Sub
    This technique requires that you map the content controls to a CustomXMLPart which Graham's tool facilitates or you can use mine: https://gregmaxey.com/word_tip_pages...rt_Dialog.html

    I have attached a working example (I did not change the CC titles that Graham used).
    Attached Files Attached Files
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •