Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    ComboBox, added programatically, won't fill (Word97 (NT))

    Hi

    I'm developing a set of macros to programatically add controls to a dialog box. (The macros gets a list of what's to be added from a table in a separate Word document.)

    Everything works okay, except for combo boxes. I can add the combo box, but when I try to fill it the control doesn't have a method of AddItem. An error message tells me that the control is read only.

    For example, if I go:

    Set MyControl = Controls("Fields").Add("Forms." & MyArray(5, MyCounter) & ".1")

    ... "Fields" is the name of a Multipage control, and "MyArray(5, MyCounter)" resolves to "ComboBox" ...

    ... the combo box gets added, but MyControl doesn't have a method of AddItems, which means I can't fill it.


    Any ideas?
    Dale

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

    Re: ComboBox, added programatically, won't fill (Word97 (NT))

    AFAIK, you don't add a control to a multipage control, but to one of its pages:

    Set MyControl = Me.Controls("Fields").Pages(0).Controls.Add(...)

    You can omit .Controls both times if you like, since it's the default property. So it would become

    Set MyControl = Me("Fields").Pages(0).Add(...)

    You can even omit .Pages, since that is the default property of a multipage control:

    Set MyControl = Me("Fields")(0).Add(...)

    But that doesn't improve the readability and maintainability of your code, in my opinion.

    To add items to a combo box, you can use the AddItem method (not AddItems; in your post, you mention AddItem first, then AddItems later on) or the List property:

    MyControl.AddItem "Hello"
    MyControl.AddItem "World"

    or

    MyControl.List() = MyArray

    Both should work if you have declared MyControl as Control, but if that doesn't work, you might try to declare it as ComboBox.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: ComboBox, added programatically, won't fill (Word97 (NT))

    Thanks, Hans

    Redeclaring it as a combo box did the trick. Thanks very much for your help

    Dale

Posting Permissions

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