ADODB.Connection & ADODB.Recordset - User define type not defined
Asked Answered
M

1

5

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?

Maxine answered 4/7, 2018 at 16:8 Comment(4)
Like it highlights Set cn = New ADODB.Connection?Skindeep
No. It is highlights Dim cn As ADODB.Connection @SkindeepMaxine
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.Twelve
Thanks @Jeeped. It worked.Maxine
T
11

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

Twelve answered 4/7, 2018 at 16:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.