VBA - Combo Box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gozzer101
    New Member
    • Nov 2006
    • 8

    #1

    VBA - Combo Box

    I want a combobox in an userform which has a list of values already in the dropdown bar. Im quite new with vba and I'm stuck with this. I think I can use the rowsource property but this means I have to put some data into a worksheet, which I would prefer to avoid as I only want a userform

    Thank you in advance for your help!
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by gozzer101
    I want a combobox in an userform which has a list of values already in the dropdown bar. Im quite new with vba and I'm stuck with this. I think I can use the rowsource property but this means I have to put some data into a worksheet, which I would prefer to avoid as I only want a userform
    Try looking into the .AddItem method, if you want to do it from VBA. If you want to just fill in a list at design time, you set the RowSourceType property to "Value List", and fill in the list in the RowSource property.

    Comment

    • gozzer101
      New Member
      • Nov 2006
      • 8

      #3
      Originally posted by Killer42
      Try looking into the .AddItem method, if you want to do it from VBA. If you want to just fill in a list at design time, you set the RowSourceType property to "Value List", and fill in the list in the RowSource property.

      Thanks for the reply!

      Still having trouble with this. VBA recognizes .rowsourcetype in the code, but how do i assign it to value list? I have tried the following
      combobox1.rowso urcetype = value list
      combobox1.rowso urcetype = "value list"
      combobox1.rowso urcetype [=value list]

      Nothing seems to work though.

      The .additem method I gave a go too. I tried combobox1.addit em ([Exampledata1, Example data2, Exampledata3])

      Had no luck here either, could you possibly give me an example code to work with? Or tell me how to set the rowsource tpye to value list which will then let me enter values into the properties window of the userform.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by gozzer101
        Still having trouble with this. VBA recognizes .rowsourcetype in the code, but how do i assign it to value list? I have tried the following
        combobox1.rowso urcetype = value list
        combobox1.rowso urcetype = "value list"
        combobox1.rowso urcetype [=value list]
        Nothing seems to work though.
        I don't know, maybe it's case sensistive. The online help says to set it to "Value List".

        Originally posted by gozzer101
        The .additem method I gave a go too. I tried combobox1.addit em ([Exampledata1, Example data2, Exampledata3])
        For one thing, AddItem probably won't run until the RowSourceType has been set correctly. For another, you use it to add one string item at a time. So your example should be more like
        Code:
        combobox1.additem "Exampledata1"
        combobox1.additem "Example data2"
        combobox1.additem "Exampledata3"
        Originally posted by gozzer101
        Had no luck here either, could you possibly give me an example code to work with? Or tell me how to set the rowsource tpye to value list which will then let me enter values into the properties window of the userform.
        The simplest way would be to set Row Source Type in the properties window. You can find it under the Data or All tabs. (In Access 2003, that is. Don't know about other versions.)

        Comment

        Working...