Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    Feb 2006
    Location
    Washington, District Of Columbia
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form: Using Dropdown field to Autofill (2003)

    Hi,

    I'm creating a form that asks a series of questions. Based on what they choose the response is filled in. I know I'm going to have to run a macro on exit and set to calculate on exit but I don't know how to write macros. I have the dropdowns bookmarked and the location of where I want the answer to appear bookmarked. How can I write an IF macro to do this for me. I've attched the doc as a sample. Thanks in advance for any help you can offer

    Cris
    Attached Files Attached Files

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

    Re: Form: Using Dropdown field to Autofill (2003)

    The code could look like this:

    Sub FillAnswer1()
    Select Case ActiveDocument.FormFields("DropDown1").Result
    Dim strText As String
    Case "Please Choose One"
    strText = ""
    Case "Option 1"
    strText = "This is the text for Option 1."
    Case "Option 2"
    strText = "This is the text for Option 2." & _
    vbCr & "It consists of two lines."
    Case "Option 3"
    strText = "Three's a crowd."
    Case "Option 4"
    strText = "I'm running out of ideas."
    Case "Option 5"
    strText = "And now for something completely different."
    End Select
    UpdateBookmark "Answer1", strText
    End Sub

    Sub UpdateBookmark(BookmarkName As String, AText As String)
    Dim rng As Range
    ActiveDocument.Unprotect
    Set rng = ActiveDocument.Bookmarks(BookmarkName).Range
    rng.Text = AText
    ActiveDocument.Bookmarks.Add BookmarkName, rng
    ActiveDocument.Protect wdAllowOnlyFormFields, True
    End Sub

    FillAnswer1 is the macro that must be set as the On Exit macro for DropDown1. It takes the item selected in DropDown1 and uses a Select Case ... End Select statement to determine the text to use for the answer. It then calls the general procedure UpdateBookmark that inserts the text in the bookmark.
    Keep in mind that the On Exit macro runs when the user exits the dropdown by pressing Tab or by clicking elsewhere, not when the user selects an item from the list.

    The attached version contains the above code and also a macro FillAnswer2 for the second dropdown. It calls the same UpdateBookmark procedure.
    Attached Files Attached Files

  3. #3
    Lounger
    Join Date
    Feb 2006
    Location
    Washington, District Of Columbia
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form: Using Dropdown field to Autofill (2003)

    Thanks Hans... YOU ROCK!!!

    If I decide not to go with the dropdown list but end up doing check boxes within a frame and only allow the users to choose one of the check boxes... will I be able to use basically the same type of macro. Will that be a possible option or will the dropdown list be the way to go.

    Thanks again... you are the BEST!

    ~Cris

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

    Re: Form: Using Dropdown field to Autofill (2003)

    If you use check boxes from the Forms toolbar, it becomes more complicated because you have to handle turning off check boxes within a group yourself. Check boxes from the Control Toolbox are a very different kind of control. I'd stick with the dropdown lists.

  5. #5
    Lounger
    Join Date
    Feb 2006
    Location
    Washington, District Of Columbia
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form: Using Dropdown field to Autofill (2003)

    Thanks, Hans! I'll stick to the dropdown

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

    Re: Form: Using Dropdown field to Autofill (2003)

    Hi Cris,

    Since you're using a dropdown field, you can also generate the required output without the need for vba, or a fragile bookmark. You could instead use a field coded as per the attached.
    Attached Files Attached Files
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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