Results 1 to 4 of 4
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Populate a drop-down formfield list?

    W97 - VBA

    I would like to do the following:

    pass a value into word
    using this value than populate a drop-down form field listbox in word.

    eg the value passed is "2"
    using the 2 I then display 2 items in the dropdown form field list.
    Has anyone done this or something similiar?
    Please let me.

    TIA Diana

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Populate a drop-down formfield list?

    You've left a lot out, Diana. What do you want to show in your dropdown--which 2 (or however many) values are you going to use to populate it? Do you just want to display two rows, or do you want two specific values to be displayed?
    Charlotte

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate a word drop-down formfield list?

    Charlotte - just filling in the gaps for you -

    I pass the value '2' into Word.
    The 2 means I would like to display 2 items (or 2 rows)in the dropdown form field list.

    If the value 3 is passed,then 3 rows are to be displayed in the drop down etc.

    The data that is to appear in each row comes from:
    Another string is passed into word with data values.
    If the value 2 is passed, then obtain the first 2 items in the string.
    Display the 1st data value in row 1
    the 2nd data value in row 2 etc

    Is that clearer?
    Let me know if you require anything else?

    I've never populated a Word form field drop down list using the method of passing values into word - I would just like to know if this can be done.
    & if it has been done
    & what I need to watch out for etc.

    regards Diana

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Populate a word drop-down formfield list?

    The following code should get you started

    <pre>Dim x, n, Arr
    x = 5 'This is the passed-in value
    Arr = Array("Value 1", "Value 2", "Value 3", "Value 4", "Still going")
    With ActiveDocument.FormFields(1).DropDown.ListEntries
    .Clear 'Empties the list
    For n = 0 To (x - 1) 'arrays start counting at 0
    .Add NAME:=Arr(n) 'populates the list from the array values
    Next n
    End With</pre>

    It needs error catching (at minimum if count is greater than array) and you need to work out what the value (or name) of the FormField is.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

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