tags:

views:

60

answers:

3

I want some default values in my combo boxes but can't seem to figure out how to do this without writing a module that populates the combo boxes. How can I manually fill in the combo boxes so I don't have to use code to do something so simple.

Thanks

A: 

If I understand you question correctly, I'm fairly sure you have to have code somewhere, I don't think VBA supports as I seem to remember that VB6 did to just add the items in a property, but you don't have to create a separate module, just something like this should work:

Private Sub UserForm_Activate()
    ComboBox1.AddItem "Text1"
    ComboBox1.AddItem "Text2"
    ComboBox1.AddItem "Text3"
End Sub
ho1
Ok, that's fair. I know in Visual Studio you can do things like control the items in a drop down, but if you can't in Excel, then I guess I'll have to do it with code. Thanks!
Soo
@Soo: In .Net it cheats though, it creates the code for you. Just look in the designer.vb file for the form and you'd find something like `Me.ComboBox1.Items.AddRange(New Object() {"Text1", "Text2"})`.
ho1
@Soo In general, the VBA editor allows you to specify a source of items so that you don't have to code it -- that source is usually the document or project with which the VBA project is associated (i.e. the Excel Workbook).
Jay
A: 

I guess you speak about Access ? If that's the case,

  • set the Row Source Type to "Value List"
  • then set the Row Source to Black; Blue; Green or whatever you want
iDevlop
A: 

What program are you using? Where is the combobox. For example, in Excel, you can have a combobox on a form or on the worksheet, and the answer is going to depend on these factors.

In Excel, you can define your default values in a worksheet (which you can hide, if you want), and set the combo box source to the corresponding range -- no code required.

Please elaborate on your requirements and you'll get more specific answers.

Jay