简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM