+ Reply to Thread
Results 1 to 3 of 3

dynamically assigning to a combo box

  1. #1
    C
    Guest

    dynamically assigning to a combo box

    Forgive me as I am new to VB. I am trying to assign items to multiple combo
    box lists, selecting the combo box dynamically. There has to be a very
    simple way to set a string or value into the parent object of the combo box
    that will then dynamically set the combo box object itself. In a simple
    version, I am trying to set values into combo boxes named ProductList1 to
    ProductList10:

    Private Sub LoadComboBox_Click()
    Dim i As Integer
    For Each validcell In Worksheets("Product List").Range("A2:A100")
    For i = 1 To 10
    If validcell.Value > 0 Then

    ' This of course will work
    ProductList1.AddItem validcell

    ' As will this
    Me.[ProductList1].AddItem validcell

    ' What I need is this
    Me.["ProductList" & i].AddItem validcell

    End If
    Next i
    Next cell
    End Sub

    This has to be an easy solution, I am just not familiar with the syntax.
    Many thanks in advance.




  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello C,

    Here is the syntax you are looking for.

    Dim I As Integer

    I = 1
    Me.Controls("CombBox" & I).AddItem "Your Data"

    Hope this helps,
    Leith Ross

  3. #3

    Re: dynamically assigning to a combo box


    HTH

    ' What I need is this
    Me.Controls("ProductList" & i).AddItem validcell


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1