Excel 2003 Connection error message "User-defined type not defined"

Posted on 2009-02-17
Last Modified: 2012-05-06
From Excel 2003 need to connect to Access database.  
This line of VB code in the Visual Basic Editor    
Dim cnn As ADODB.Connection  
always gives error message : "User-defined type not defined"

Dim cnn As ADODB.Connection

Set cnn = New adodb.Connection

   With cnn

      .ConnectionTimeout = 500

      .Provider = "Microsoft.Jet.OLEDB.4.0"

      .ConnectionString = "Data Source=" & strPathToDB & ";"


      .CommandTimeout = 500

   End With

Open in new window

Question by:OceanStars
    LVL 22

    Accepted Solution

    This means that you have not referened the ADODB library.

    In your VBA editor. goto tools->references and add reference to Microsoft ActiveX Data Objects library


    Author Closing Comment

    Thank you.  I just found the answer myself.  You are fast!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
    To stay competitive, modern businesses must adapt and stay innovative, and this is increasingly only possible by working with outside talent. Managers and executives have understood the power of outsourcing for quite some time, but traditional clien…
    The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
    This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

    779 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

    15 Experts available now in Live!

    Get 1:1 Help Now