Search code examples
vbaobjectms-accesscollections

Determining whether an object is a member of a collection in VBA


How do I determine whether an object is a member of a collection in VBA?

Specifically, I need to find out whether a table definition is a member of the TableDefs collection.


Solution

  • Your best bet is to iterate over the members of the collection and see if any match what you are looking for. Trust me I have had to do this many times.

    The second solution (which is much worse) is to catch the "Item not in collection" error and then set a flag to say the item does not exist.