User-defined type not defined

You can create your own data types in Visual Basic, but they must be defined first in a Type...End Type statement or in a properly registered object library or type library. This error has the following causes and solutions:

  • You tried to declare a variable or argument with an undefined data type or you specified an unknown class or object.

    Use the Type statement in a module to define a new data type. If you are trying to create a reference to a class, the class must be visible to the project. If you are referring to a class in your program, you must have a class module of the specified name in your project. Check the spelling of the type name or name of the object.

  • The type you want to declare is in another module but has been declared Private. Move the definition of the type to a standard module where it can be Public.

  • The type is a valid type, but the object library or type library in which it is defined isn't registered in Visual Basic. Display the References dialog box, and then select the appropriate object library or type library. For example, if you don't check the Data Access Object in the References dialog box, types like Database, Recordset, and TableDef aren't recognized and references to them in code cause this error.

For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh).

See also

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.