Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Aug 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word form macro question (2002/2003)

    I have a question about a macro in a word form. I have two drop down lists on a word form. when the user selects an item from the first, I want the second to select the item at the same index.

    Ie.

    Drop down one;

    Item A
    Item B
    Item C
    Item D


    Drop Down Two;
    Item 1
    Item 2
    Item 3
    Item 4


    If the user selects 'Item C' from drop down one, I want drop down two to show 'Item 3'.

    Olly

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word form macro question (2002/2003)

    Welcome to Woody's Lounge.

    Could you clarify whether you are talking about
    1. <LI>Dropdown lists on the document itself, created from the Forms toolbar, or
      <LI>Combo boxes on the document itself, created from the Control Toolbox, or
      <LI>Combo boxes on a userform created in the Visual Basic Editor.
    Should the user be able to change the selected item in the second dropdown list?

  3. #3
    New Lounger
    Join Date
    Aug 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word form macro question (2002/2003)

    [img]/forums/images/smilies/smile.gif[/img]

    I am currently using drop downs from the forms toolbar, however, I am happy to use which ever one is the most suitable in this situation.

    Olly

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word form macro question (2002/2003)

    Each dropdown from the Forms toolbar has an associated bookmark name; you can see it if you double click the dropdown while the document is unprotected. The default names are Dropdown1, Dropdown2 etc. Note the names of your dropdowns.

    Select Tools | Macro | Macros...
    Enter UpdateDropdown2 in the 'Macro name' box.
    Make sure that your document is selected in the 'Macros in' box, not Normal.dot.
    Click 'Create'.
    Make the macro look like this:

    Sub UpdateDropdown2()
    '
    ' UpdateDropdown2 Macro
    ' Macro created ... by ...
    '
    ActiveDocument.FormFields("Dropdown2").DropDown.Va lue = _
    ActiveDocument.FormFields("Dropdown1").DropDown.Va lue
    End Sub

    using the correct names.
    Switch back to Word.
    Double click the first dropdown, and select UpdateDropdown2 in the (Run macro on) Exit box.
    Now protect the document for forms.
    If you select an item in the first dropdown, and move to the next form field, the second dropdown will be updated.

  5. #5
    New Lounger
    Join Date
    Aug 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word form macro question (2002/2003)

    Thanks.

    I put that in, and set it up, and its only kind of working. If then select itemB from the first drop down, nothing happens to the second drop down, UNTIL you click on the second drop down and then the "Select Value" default entry suddenly changes to the correct entry in the list.

    If i select an entry in drop down 1, unlock the form then manually run the macro drop down 2 changes fine. Also, and i dont know if this helps, if i highlight the main line of that code and set a debug point, then lock the form and change the value of drop down one, it doesnt stop on that line.

    I have tried placing the code in both the Normal.dot section of the macro editor, as well as the document itself.

    ANy ideas ?

  6. #6
    New Lounger
    Join Date
    Aug 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word form macro question (2002/2003)

    An update.

    It does work with the form locked IF the user uses the TAB key to move away from the first drop down. If the user selects the entry with the mouse, then clicks on the next form entry (in this case a text area) it doesnt update dropdown2, it does work if they use the tab key though.

    Olly

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word form macro question (2002/2003)

    This is a limitation of the form fields from the Forms toolbar. They only react to the user entering or leaving the field; not to a change in the field itself.

    The combo box from the Control Toolbox has many more events you can handle, among which an On Click event. Downside is that you must populate it in code, for example in the Document_Open event in ThisDocument. See the attached zipped example.

    If you want to edit the combo boxes, display the Control Toolbox toolbar and click the Design Mode button.
    Attached Files Attached Files

Posting Permissions

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