Solved

Excel ADO error:  User-defined type not defined

Posted on 2010-11-12
5
492 Views
Last Modified: 2012-06-21
I'm trying to just pull a single SQL 2005 table, one way, into Excel 2003.

Compile error:
User-defined type not defined

I have references set to both Microsoft ADO Ext. 2.8 for DDL and Security and Microsoft ActiveX Data Objects Recordset 2.8 Library

What am I doint wrong?
The below VBA is in the Workbook Open event  in "ThisWorkbook".  It's a newly created Excel worksheet with nothing but this code in it and the references I mentioned added from "Tools|References".
Private Sub Workbook_Open()

'This was set up using Microsoft ActiveX Data Objects version 2.8 (In Microsoft Visual Basic, select Tools, References)

Worksheets("Sheet1").Range("B2:BZ65535").Clear



Dim cnt As ADODB.Connection

Dim rst As ADODB.Recordset

Dim stSQL As String

Dim wbBook As Workbook

Dim wsSheet As Worksheet

Dim rnStart As Range





Const stADO As String = "Provider=SQLOLEDB.1;Integrated Security=SSPI; " & _

"Persist Security Info=False; " & _

"Initial Catalog=CustomerComplaints; " & _

"Data Source=BETASERVE"



Set wbBook = ActiveWorkbook

Set wsSheet = wbBook.Worksheets(1)



With wsSheet

Set rnStart = .Range("B2")

End With



stSQL = "SELECT * FROM Complaints ORDER BY Location, DateReceived"



Set cnt = New ADODB.Connection



With cnt

.CursorLocation = adUseClient

.Open stADO

.CommandTimeout = 0

Set rst = .Execute(stSQL)

End With



'Here we add the Recordset to the sheet from A1

rnStart.CopyFromRecordset rst



'Cleaning up.

rst.Close

cnt.Close

Set rst = Nothing

Set cnt = Nothing



End Sub

Open in new window

0
Comment
Question by:megnin
  • 2
5 Comments
 
LVL 24

Accepted Solution

by:
broomee9 earned 500 total points
ID: 34124717
Re-posting as Expert Comment:

Instead of referencing this:
Microsoft ActiveX Data Objects Recordset 2.8 Library

Reference this:
Microsoft ActiveX Data Objects 2.8 Library
0
 
LVL 1

Author Comment

by:megnin
ID: 34124750
You are brilliant!  :-)  Thank you.  That did the trick.  I missed that because instead of that option being down in the alphabetical listing with the Microsoft..... stuff it was up near the very top of the list of references.  Just not close enough to the top for me to notice it. ;-)
0
 
LVL 1

Author Closing Comment

by:megnin
ID: 34136787
Thank you that fixed it.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
need summation of cells of the same row  having same column difference between the two cells 6 35
Macro Capitalize 4 54
Delete texts with font color 16 30
ADD New Entries 7 16
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now