Dim Cn As New Adodb.connection Compile Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the compile error user-defined type not defined excel 2013 company Business Learn more about hiring developers or posting ads with us Stack Overflow
Adodb.connection Vba Excel
Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 adodb.connection vba reference million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Compiler Error: User-defined types not defined up vote 11 down vote favorite 1 I get the compile-time error "User-defined
Excel Vba Adodb Reference
types not defined" on this line: Dim cn As ADODB.Connection` What could be wrong? Code: Sub test() Dim cn As ADODB.Connection 'Not the best way to get the name, just convenient for notes strFile = Workbooks(1).FullName strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";" Set cn = CreateObject("ADODB.Connection") 'For this to work, you must create a DSN and use the name in place of 'DSNName 'strSQL = "INSERT INTO [ODBC;DSN=DSNName;].NameOfMySQLTable " microsoft activex data objects 2.5 library & "Select AnyField As NameOfMySQLField FROM [Sheet1$];" strSQL = "SELECT F1 FROM [Sheet1$];" cn.Execute strSQL End Sub excel vba excel-vba share|improve this question edited Jan 30 '15 at 14:27 pnuts 33.7k63569 asked Mar 18 '11 at 8:27 Parth Bhatt 13.1k24105200 add a comment| 3 Answers 3 active oldest votes up vote 19 down vote accepted I had forgotten to add a reference to "Microsoft ActiveX Data Objects 2.5 Library": Tools > References > Check the checkbox in front of "Microsoft ActiveX Data Objects 2.5 Library" share|improve this answer edited Apr 23 '13 at 11:09 Jean-Francois Corbett 23.9k1678113 answered Mar 18 '11 at 8:43 Parth Bhatt 13.1k24105200 add a comment| up vote 7 down vote You can use late binding: Dim cn As Object will make the problem go away. VBA will make the reference automatically when the CreateObject("ADODB.Connection") statement is executed. share|improve this answer edited Apr 23 '14 at 6:49 answered Mar 19 '11 at 11:45 Jean-Francois Corbett 23.9k1678113 @Jean-FrancoisCorbett Seems like the only way I can get this working is by adding the reference... Possible that I don't understand your solution. –Shrout1 Sep 6 '13 at 18:26 Tested Dim cn As Object: Set cn = CreateObject("ADODB.Connection") at this end, works fine. Are you really getting the same error as before? –Jean-Franc
360 games PC games
Excel Adodb Recordset
Windows games Windows phone games Entertainment All Entertainment
How To Add Microsoft Activex Data Objects 2.8 Library
Movies & TV Music Business & Education Business Students & educators vba tools references greyed out Developers Sale Sale Find a store Gift cards Products Software & services Windows Office Free downloads & security Internet http://stackoverflow.com/questions/5349580/compiler-error-user-defined-types-not-defined Explorer Microsoft Edge Skype OneNote OneDrive Microsoft Health MSN Bing Microsoft Groove Microsoft Movies & TV Devices & Xbox All Microsoft devices Microsoft Surface All Windows PCs & tablets PC accessories Xbox & games Microsoft Lumia All https://support.microsoft.com/en-us/kb/858611 Windows phones Microsoft HoloLens For business Cloud Platform Microsoft Azure Microsoft Dynamics Windows for business Office for business Skype for business Surface for business Enterprise solutions Small business solutions Find a solutions provider Volume Licensing For developers & IT pros Develop Windows apps Microsoft Azure MSDN TechNet Visual Studio For students & educators Office for students OneNote in classroom Shop PCs & tablets perfect for students Microsoft in Education Support Sign in Cart Cart Javascript is disabled Please enable javascript and refresh the page Cookies are disabled Please enable cookies and refresh the page CV: {{ getCv() }} English (United States) Terms of use Privacy & cookies Trademarks © 2016 Microsoft
TipsBlackBerry TipsDesign TipsFirefox TipsiPad TipsiPhone TipsJoomla TipsInternet Explorer TipsSmartPhone TipsMicrosoft Excel TipsMicrosoft Word TipsMicrosoft PowerPoint TipsOutlookWindows http://www.itjungles.com/fixed-error-adodb-connection-user-defined-type-not-defined.html Phone 7Palm TipsWeb HostingSamsung TipsHTC TipsMOTOROLA TipsNokia TipsSearch Engine OptimizationElectronic AccessoriesSocial MediaInternetPrintersWindows PhoneWeb DevelopmentArticlesGeneral ArticlesReal Estate FormsRemote ControlsOperating SystemWindows VistaWindows 7Windows ServerWindowsOS X Tweet Author: Jenny Nguyen compile error Fixed: Error ADODB.Connection User-defined type not defined Tweet While I was try trying to query some data from SQL Server 2005 in Excel VBA Macro I get an microsoft activex data error: ---------------------------Microsoft Visual Basic---------------------------Compile error: ADODB.Connection User-defined type not defined---------------------------OK Help --------------------------- To fix this problem I just need to add a reference to the project. Here's how: 1. Click on Tools. 2. Click on References.... 3. Ensure you have Microsoft ActiveX Data Objects selected. Now try to run your Macro again and you should not encouter the error. * iOS Development * OS X * Product Review Amazon.com Widgets Scroll to Top Privacy Policy - Copyright 2009