myParms.colCap.Item(9) = "Opened from" <== 'object required' error
Can anyone see the problem?
Yup. You need to brush up on the use of the .Add method of the Collection
object.
myparams.colCap.Add Item:="Opened from ", Key:= "9"
or
myparams.colCap.Add "Opened from ","9"
to retrieve a value:
somestring = myParams.colCap.Item("9")
Note that:
somestring = myParams.colCap.Item(9)
is *not* the same thing. That would retrieve the 9th item in the collection
(if there is one).
If you use a number as the Item argument, the item from that position within
the collection will be returned. If you use a string argument, the item
*with that specific key designation* will be returned.
As written, .Item("9") and .Item(1) would both point to the same member of
the collection.
Alternatively, you could:
For i = 1 to 10
' Add 10 empty strings to collection and give them keys "1" to "10".
myparams.ColCap.Add "",cstr(i)
Next i
If you did that, then:
myParms.colCap.Item(9) = "Opened from"
or
myParms.colCap.Item("9") = "Opened from"
would both change the same pre-existing member of the collection.
Note: I have a vague recollection that you can't use a custom collection as
a data type within a user-defined type, but it is a vague memory and details
are fuzzy, so I'm not sure. I do seem to recall having to create a custom
Class (where a custom collection isn't a problem), rather than a Type, as a
workaround. In any case, I may have been trying to do something entirely
different. If that were the problem you would be getting a "...user defined
type not allowed..." error, so you don't need to panic unless that pops up,
but I thought it worth at least a heads-up.