Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Utah, USA
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    macro (word 2000)

    I have a word doc with a drop down menu and two text boxes. I'm looking for a macro to fire when an item is selected in the drop down menu that will fill in the two text boxes.

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

    Re: macro (word 2000)

    Can you tell us how you created the drop down menu and the text boxes? (From the Forms toolbar, or from the Control Toolbox, or otherwise)

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Utah, USA
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: macro (word 2000)

    Using the form tool. The document where tis dropdown and text boxes reside is password protected as well.

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

    Re: macro (word 2000)

    If you double click the form dropdown while the document is unprotected, you can specify an on exit macro. This macro can inspect the value of the dropdown and set the value of the text boxes accordingly. I have attached a simple example. Make sure that macro security is not set to High when you open the document.
    You can view the macro in the Visual Basic Editor.
    Attached Files Attached Files

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Utah, USA
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: macro (word 2000)

    Thanks, this is great

  6. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: macro (word 2000)

    Hi Daniel,

    You can also achieve the same result without a macro, using formula fields and setting the drop-down's properties to 'calculate on exit'. The attached modification of Hans' solution shows how. To see how the field coding is done, use Alt-F9 to toggle the field code display on/off.
    Attached Files Attached Files
    Cheers,

    Paul Edstein
    [MS MVP - Word]

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

    Re: macro (word 2000)

    Avoiding macros can be a real asset in some situations. However, if the original poster wants to be able to edit the description or unit price after selecting a product, an IF field won't work. Also, Word doesn't translate the number format of the unit price field correctly for continental Europe.

  8. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: macro (word 2000)

    Hi Hans,

    If you want to be able to edit the description afterwards, simply wrap the lot in a FILLIN field and make the IF test's result the default FILLIN value. See attached.

    As for the numeric result formatting, hard-coding it in vba has its own problems - your code gives a result with '.' as the thousands separator and ',' as the decimal seprataor, which is not a valid currency format where I am - and the values are displayed 100 times what the vba code says they should (eg 0.3 shows as
    Attached Files Attached Files
    Cheers,

    Paul Edstein
    [MS MVP - Word]

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

    Re: macro (word 2000)

    The number format is messed up in both versions when the document is moved between systems with a different decimal separator, it appears. The original poster can decide which version to use.

Posting Permissions

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