Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    May 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro in a form (2003)

    In an editable form, I would like to automatically populate a Yes or No check box based on the selection the user makes in the previous drop-down list of names. My guess is that I need a macro (VBA?) to do this. Has anyone ever done this?

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

    Re: Macro in a form (2003)

    Welcome to Woody's Lounge!

    Unprotect the document if necessary.
    Double click the dropdown form field and the check box form field, and set their bookmark names to something meaningful.
    Activate the Visual Basic Editor (Alt+F11).
    Insert a new module (Insert | Module)
    Enter a macro like this arbitrary example, or copy / paste from this post and modify as needed:

    Sub SetTax()
    Select Case ActiveDocument.FormFields("State").Result
    Case "MA", "ME", "VT"
    ActiveDocument.FormFields("Tax").CheckBox.Value = True
    Case Else
    ActiveDocument.FormFields("Tax").CheckBox.Value = False
    End Select
    End Sub

    In the above example, "State" is the name of the dropdown, and "Tax" is the name of the check box.
    Switch back to Word (Alt+F11).
    Double click the dropdown form field again.
    Select the name of the macro (SetTax in the above example) in the Exit box (in the 'Run macro on' section).
    Finally, protect the document for forms to test.

    Note: the check box will be updated when the user leaves the dropdown, not when the user selects an item.

    See the attached example.
    Attached Files Attached Files

  3. #3
    Lounger
    Join Date
    May 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro in a form (2003)

    Thanks for the prompt reply to my first-ever post! I've followed your directions, but I haven't succeeded yet--the check box doesn't check. I must have missed something, so I'll keep trying.

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

    Re: Macro in a form (2003)

    Make sure that macro security is not set to High (in Tools | Macro | Security), as this would prevent macros from running. Medium is the best setting; you'll be prompted to enable macros when you open the document.
    And keep in mind that selecting an item from the dropdown list is not enough, you must tab out of the dropdown list to see the effect.

  5. #5
    Lounger
    Join Date
    May 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro in a form (2003)

    Success! It wasn't the security issue. Rather, I had the Check Box Enabled selected in the check box dialog box. When I looked back in your file, I noticed my error. Many thanks!

Posting Permissions

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