0

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?

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
Biel
  • 193
  • 1
  • 3
  • 15
  • 1
    You [cannot](https://stackoverflow.com/questions/68460458/is-it-possible-to-assign-values-to-array-without-looping-vba#comment120991520_68460458) have `astrSomethingList = Array(...)`. You also should consult the [documentation for `List`](https://learn.microsoft.com/en-us/office/vba/api/outlook.combobox.list) and/or https://stackoverflow.com/a/24889461/11683, having established that you are indeed using VB6/A and not VB.NET. – GSerg Jul 26 '21 at 10:25
  • @GSerg Thank you, I will check the documentation first next time. – Biel Jul 26 '21 at 10:38
  • 1
    It would help if you knew what language you were writing in. Did you read the descriptions of the tags you used? It would seem not, because this cannot be a VB.NET question and a VB6 question. It is either one or the other. Given that a VB.NET ComboBox has no List property, I'm guessing it's VB6. You should know. – jmcilhinney Jul 26 '21 at 10:39
  • @jmcilhinney It is VB6 yes, sorry for the confusion this caused. I am new to VB and did not check the differences before asking, my bad. – Biel Jul 26 '21 at 10:41

1 Answers1

2

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.

User51
  • 887
  • 8
  • 17
  • Thank you! I read the docs later but was still a little bit confused and thought `.List()` was settable, but I wasn’t doing it right. This helped me a lot. – Biel Jul 26 '21 at 18:28