Runtime Error 385: “Need property-array index,” explained and fixed

Error 385, “Need property-array index”, fires when code uses a property array as though it were a single value, omitting the index that selects an element. Properties such as a list control's List or Selected, and control arrays themselves, only exist element by element; there is no whole-array value to read, assign, or pass. The statement is usually one pair of parentheses short, which makes error 385 one of the fastest errors to fix once recognized, and one of the most confusing before, because the property name itself looks complete.

For people who just run the program

  1. This is a coding error, full stop. It appears in macros and programs when a statement forgets to say which element of a list-like property it wants; no document content causes it.
  2. Note the action. Actions that copy, display, or save the contents of a list or a group of controls are the usual sites.
  3. Retrying changes nothing. The missing index is missing on every run.
  4. Pass on the number. Error 385 is so specific that an experienced maintainer will know the shape of the fix before opening the code.

For people who write the code

  1. Add the index that selects the element. The contrast is the whole lesson:
  2. firstItem = lstOrders.List        ' error 385: which element?
    firstItem = lstOrders.List(0)     ' the property array, indexed
    count = lstOrders.ListCount       ' the count is a separate property
  3. Use the count property for counts. Code that tries to size or loop from the property array itself should read ListCount (or the control-specific equivalent) and then index from 0 to count minus 1.
  4. Control arrays behave the same way. Referencing a control array by name without an index, to set a property “on all of them,” is error 385. Loop the array and set each element, or use a For Each over the controls collection with a type check.
Error 385 is not an out-of-range complaint. That is error 381, where an index was supplied and wrong. Error 385 means no index was supplied at all. The two are neighbors in number and opposites in cause, and confusing them sends debugging in the wrong direction.

If it still happens

If an index is visibly present and 385 still fires, the expression may be indexing the wrong thing: a property that returns a property array (a control's property that is itself indexed) needs both selections written out. Break the expression into steps with a variable per level and the missing level shows itself.

Common questions

What is a property array? A property accessed with an index, like List(2) for the third item of a list control. Because the value lives per element, using the property without an index is meaningless, which is what error 385 reports.

How do I get all the elements at once? Loop from 0 to the count minus 1 and collect them, or use a bulk property if the control offers one. There is no single statement that returns a VBA property array as a whole.

Related errors

Runtime Error 381 · Runtime Error 382 · Runtime Error 380