Compiler Error: User-defined types not defined
Solution 1:
I had forgotten to add a reference to "Microsoft ActiveX Data Objects 2.5 Library": This reference is required for early binding
.
How to get to that reference:
Tools > References > Check the checkbox in front of "Microsoft ActiveX Data Objects 2.5 Library"
Other libraries that work include:
Microsoft ActiveX Data Objects 2.6 Library
Microsoft ActiveX Data Objects 2.7 Library
Microsoft ActiveX Data Objects 2.8 Library
Microsoft ActiveX Data Objects 6.1 Library
Solution 2:
You can use late binding:
Dim cn As Object
will make the problem go away. VBA will make the reference automatically when the Set cn = CreateObject("ADODB.Connection")
statement is executed.