Search code examples
arrayscomboboxvb6

Setting String Array as Combobox List gives Argument is required error in Visual Basic


So I have a String array declared as this:

Dim astrSomethingList() As String: astrSomethingList = _ 
    Array("01", "02", "03", "04", "05", "06", "07", "08", "20")

And then I try to assign this array to a ComboBox I have in a form, like this:

With m_form

    ...
    
    .cboQuerySomething.List = astrSomethingList

    ...
    
End With

But when I try to compile and run it, it gives me the error The argument is not optional and refers to the .List = part of the code.

I have tried using

Set .cboQuerySomething.List = astrSomethingList

instead, but it does not work either.

What am I missing?


Solution

  • For VB6 Combo Boxes, first call .Clear and then loop through the values and use .Add on each item individually

    .List() in a VB6 Combobox is an indexed property, not a settable field. There is no way to set the entire list at once, but it would be simple to create a helper module with commonly executed tasks.