# Exists
{: .no_toc }

Returns **True** if a specified key exists in a **Collection** object; **False** if it does not.

Syntax: *object*.**Exists(** *key* **)**

*object*
: *required* An object expression that evaluates to a **Collection** object.

*key*
: *required* A **String** value identifying the item to locate in the collection.

> [!NOTE]
>
> **Exists** is a twinBASIC extension; the classic VBA **Collection** object has no **Exists** method. The same effect in VBA requires calling [**Item**](/tB/Modules/Collection/Item.md) inside an error-handling block.

Key comparison is governed by the [**KeyCompareMode**](/tB/Modules/Collection/KeyCompareMode.md) property.

### Common Errors

| Error | When |
|---|---|
| [94 (`&H5E`)](/Reference/Run-time-Errors.md#94), *Invalid use of Null* | *key* is **Null** |

### Example

```tb check_build
Dim MyCollection As New Collection
MyCollection.Add "alpha", Key:="a"
MyCollection.Add "beta",  Key:="b"

If MyCollection.Exists("a") Then
    Debug.Print "Key 'a' is in the collection."
End If

If Not MyCollection.Exists("z") Then
    Debug.Print "Key 'z' is not in the collection."
End If
```

### See Also

- [Add](/tB/Modules/Collection/Add.md) method
- [Item](/tB/Modules/Collection/Item.md) method
- [Keys](/tB/Modules/Collection/Keys.md) method
- [KeyCompareMode](/tB/Modules/Collection/KeyCompareMode.md) property
