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?

4
  • 1
    You cannot have astrSomethingList = Array(...). You also should consult the documentation for List and/or stackoverflow.com/a/24889461/11683, having established that you are indeed using VB6/A and not VB.NET. Commented Jul 26, 2021 at 10:25
  • @GSerg Thank you, I will check the documentation first next time. Commented Jul 26, 2021 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. Commented Jul 26, 2021 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. Commented Jul 26, 2021 at 10:41

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.