I get the compile-time error \"User-defined types not defined\" on this line:
Dim cn As ADODB.Connection
What could be wrong?
Code:
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.
Set cn = CreateObject("ADODB.Connection")