Results 1 to 3 of 3

Thread: [RESOLVED] How to load several comboboxes with the same list

  1. #1

    Thread Starter
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Resolved [RESOLVED] How to load several comboboxes with the same list

    Back again hoping to be rescued

    I have a Word 2003 userform that contains a series of combo boxes. Six of these comboboxes contain the same (long list) of items. To load these items I am simply using the .additem method.

    This works fine and I have simply copied and pasted the same code 6 times. However, I would assume that there is a better way of doing it so that I only have to write the list once, thus shortening the code? I have searched google and vba help but can find nothing.

    Any ideas appreciated.
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: How to load several comboboxes with the same list

    You could move the adds into a seperate procedure that take a combox as an argument and then call that proce for each of your comboboxes.

    Heres some pseudo-code to get you started.

    VB Code:
    1. Sub main()
    2.      PopulateCombo Me.ComboBox1
    3.      PopulateCombo Me.ComboBox2
    4.      'etc
    5. End Sub
    6.  
    7.  
    8.  
    9. Sub PopulateCombo(MyCombo As MSForms.ComboBox)
    10.     MyCombo.AddItem "Item1"
    11.     MyCombo.AddItem "Item2"
    12.     MyCombo.AddItem "Item3"
    13.     MyCombo.AddItem "Item4"
    14.     MyCombo.AddItem "Item5"
    15.     MyCombo.AddItem "Item6"
    16. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Re: How to load several comboboxes with the same list

    Thanks (again) DKenny - worked a treat
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

Posting Permissions

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



Click Here to Expand Forum to Full Width