User-defined type not defined

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
693
I have a bit of code which usually opens up an ADODB connection, runs some sql and then returns the data to excel.

This works perfectly in 1 workbook, however when I copied over the code to a new workbook it is falling down right at the start giving me the message 'user-defined type not defined'

This is the beginning of the code

Code:
 Sub myConnection()
 
 Dim cnn As ADODB.Connection
 
   Dim MyRecordSet As ADODB.Recordset
   Dim SqlString As String
   Set cnn = New ADODB.Connection

and it falls down on the line 'Dim cnn As ADODB.Connection'

Any idea why this might be?
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Tools -> References -> Microsoft ActiveX Data Objects 2.8 Library
 
Upvote 0
Thanks, I thought it might have been to do with the references (although am unsure why they're different). Wouldn't have had a clue which to turn on though. Thanks
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,308
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top