acolls_badger
acolls_badger

Reputation: 463

VBA User Defined Type not defined error

I am trying to write a vba script to run a SQL Select script and import the data into a named range in Excel, below is my code;

Option Explicit
Dim cnt As ADODB.Connection
Dim rcrds As ADODB.Recordset

Public Sub Update_Scorecard_2()

Dim ssql As String
Dim myrange As Range

Application.ScreenUpdating = False

Set cnt = New ADODB.Connection

    cnt.Open "Provider=MSDAORA;Data Source=ODSPRD01;user ID=DWH_ADH;password=mypassword;"

Call runQuery(Range("DATA_DUMP_SQL").Value, Range("DATA_DUMP"))

cnt.Close

End Sub

I am getting the error "User Defined Type Not Defined" on the line

   Dim cnt As ADODB.Connection

I do not see how this type is undefined as that is the line where I am defining it.

What mistake am I making?

Upvotes: 1

Views: 2188

Answers (1)

Jason Faulkner
Jason Faulkner

Reputation: 6558

Make sure you have the reference to "Microsoft ActiveX Data Objects Library" set in your project (Under the Project > References menu):

If you do not have this set, the runtime environment doesn't know about the ADODB library so it throws a not defined error.

Upvotes: 1

Related Questions