Visual Basic Reference

Key Property (ActiveX Controls)

See Also   Example   Applies To

Returns or sets a string that uniquely identifies a member in a collection.

Syntax

object.Key [= string]

The Key property syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
string A unique string identifying a member in a collection.

Remarks

If the string is not unique, an error will occur.

You can set the Key property when you use the Add method to add an object to a collection.

The value of the Index property of an object can change when objects in the collection are reordered, such as when you set the Sorted property to True. If you expect the Index property to change dynamically, refer to objects in a collection using the Key property.

In addition, you can use the Key property to make your Visual Basic project "self-documenting" by assigning meaningful names to the objects in a collection.