Consulting

Results 1 to 11 of 11

Thread: Dependent Drop Down List

  1. #1

    Dependent Drop Down List

    Hello,

    I am a complete noob but very much looking forward to learning.

    I have two drop down lists which contain names. I would like to be able choose an item in the first list and, that this action, prompts the second list to choose the same item.

    I have seen code which populates different choice, but being a noob, I haven't been able to figure out how to simply copy the first choice.

    I would very much appreciate one of your beasts to help me.

    --Mellowest.

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I have two drop down lists which contain names. I would like to be able choose an item in the first list and, that this action, prompts the second list to choose the same item.
    Are you saying the choice made in the first dropdown FORCES the second dropdown to become the same choice? Are the items in both dropdowns exactly the same?
    how to simply copy the first choice.
    Not sure what you mean by copy.

    Plus, what kind of "dropdowns" are you using? For example, are they text formfields in the document? In which case, yes you certainly can do what you ask with OnExit macro - when you leave one formfield (dropdown), makes the other dropdown formfield have a given value.

    Why do you want two different things to have the same value, especially if they are identical (they have the same list)?

  3. #3
    Hello Fumei,

    Thanks for your response. They are formfields, basically a list of client names that are repeated throughout the document.

    Yes, on exit from the first, the second should have the same value.

    As to your question: the form is used hundreds of times by dozens of people; it would be great timesaver.

    I hope this is clearer than my first attempt. Thank you.

  4. #4
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    "As to your question: the form is used hundreds of times by dozens of people; it would be great timesaver. "

    No that does not clear anything up for me. If the two formfields are in the same document - and have the same list - what is the gain; how does this help? In any case...[vba]Sub MakeTheOther()
    ActiveDocument.FormFields("Dropdown2").DropDown.Value = _
    ActiveDocument.FormFields("Dropdown1").DropDown.Value
    End Sub
    [/vba]With this as the OnExit macro for Dropdown1, when you select something from Dropdown1, when you Exit Dropdown1, Dropdown2 becomes the same value.

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

    Repeating Data

    Maybe that which you are looking for can be found where you are not looking:

    http://gregmaxey.mvps.org/word_tip_p...ting_data.html

    Quote Originally Posted by mellowest
    Hello,

    I am a complete noob but very much looking forward to learning.

    I have two drop down lists which contain names. I would like to be able choose an item in the first list and, that this action, prompts the second list to choose the same item.

    I have seen code which populates different choice, but being a noob, I haven't been able to figure out how to simply copy the first choice.

    I would very much appreciate one of your beasts to help me.

    --Mellowest.
    Greg

    Visit my website: http://gregmaxey.com

  6. #6
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Mellowest, this would be good for you to check out. For example, if the value of Dropdown1 is needed elsewhere, do you really need another formfield? Check out Greg's example of using a REF field. They work extremely well.

  7. #7
    --Greg,

    This might be exactly what I've been looking for. I am using Word 2007. I inserted a drop down list. Book marked it. I inserted a REF field and pointed it to the bookmark.

    Now, the one thing I cannot find is the "calculate on exit" property. I have right clicked, gone into Design mode, etc. I can pull the properties menu, but that option ins just not anywhere I can see.

    Again, thanks for that great article.

  8. #8
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,341
    Location
    It sounds like you inserted a dropdown content control (which would work only differently) instead of a formfield. The formfield controls are sort of hidden. They are in the same ribbon group. The bottom right control that looks like a folder with tools has a collection of "Legacy" forms.

    If you use the content control then you will need to use the OnExit event to update document fields.
    Greg

    Visit my website: http://gregmaxey.com

  9. #9
    Good Morning,

    That's exactly right. So, if I were to use a formfield control from the Legacy toolset, could that be used in the same manner as a dropdown list--where an user picks from a pre-selected number of items?

    If that is not the case, when you say an "OnExit" event, does that mean I would have to drive the dropdown behavior with VBA?

    Thanks for all your help.

    --Mellowest.

  10. #10
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Yes, you would use the code I posted as the OnExit macro.[vba]Sub MakeTheOther()
    ActiveDocument.FormFields("Dropdown2").DropDown.Value = _
    ActiveDocument.FormFields("Dropdown1").DropDown.Value
    End Sub [/vba]Again assuming the lists are identical.

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

    Content Control Dropdown

    I wouldn't suggest using a formfield control unless you need a protected document.

    If you use a content control dropdown or whatever, you:

    select the content control and bookmark it
    add a REF field (or fields) to the bookmark
    run the following as the ContentControl OnExit event procedure:

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    ActiveDocument.Fields.Update
    End Sub

    That event is a built-in event in the ThisDocument module, document object.
    Just add the line of code to update fields.

    Quote Originally Posted by mellowest
    Good Morning,

    That's exactly right. So, if I were to use a formfield control from the Legacy toolset, could that be used in the same manner as a dropdown list--where an user picks from a pre-selected number of items?

    If that is not the case, when you say an "OnExit" event, does that mean I would have to drive the dropdown behavior with VBA?

    Thanks for all your help.

    --Mellowest.
    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
  •