1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.