ADODB.Connection & ADODB.Recordset - User define type not defined

14,577

Go to the VBE's Tools, References then locate and put a check beside 'Microsoft ActiveX Data Objects 6.1 Library' to include the library in your project.

enter image description here

Share:
14,577
Maitreya
Author by

Maitreya

Updated on December 05, 2022

Comments

  • Maitreya
    Maitreya over 1 year

    I am facing a strange error while connecting Access DB using VBA. The VBA code goes like this:

    Sub DBC()
        Dim cn As ADODB.Connection
        Dim rs As ADODB.Recordset
    
        Set cn = New ADODB.Connection
    
        cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\Bmcstr01\grp\SRV\Allsrv\Resource Planning\Forecasting & MI\MI\backup DM\HH Complaints\Database (TCS Version)\Complaints DB.accdb;"
    
        Set rs = New ADODB.Recordset
    
        rs.Open "Access_Log", cn, adOpenKeyset, adLockOptimistic, adCmdTable
    
        rs.Filter = "ID='335266' AND Work='Test'"
        rs("Login").Value = "02/07/2018"
        rs.Update
        rs.Close
        Set rs = Nothing
        cn.Close
        Set cn = Nothing
    
    End Sub
    

    The error it is giving is: "Compile Error: User define type not defined" and it is pointing to first line of the sub.

    My table is present in the DB. It structures as follows:

    ID  Login   Work
    335266  04/07/2018  Test
    335266  03/07/2018  Test2
    

    Can anyone please help me with the reason why it is not accepting the ADODB and how to resolve this?

    • Brad
      Brad over 5 years
      Like it highlights Set cn = New ADODB.Connection?
    • Maitreya
      Maitreya over 5 years
      No. It is highlights Dim cn As ADODB.Connection @Brad
    • Admin
      Admin over 5 years
      Go to the VBE's Tools, References then locate and put a check beside 'Microsoft ActiveX Data Objects 6.1 Library' to include the library in your project.
    • Maitreya
      Maitreya over 5 years
      Thanks @Jeeped. It worked.
    • Gustav
      Gustav over 5 years
      Then please mark as answered.