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.
Author by
Maitreya
Updated on December 05, 2022Comments
-
Maitreya 6 months
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 almost 5 yearsLike it highlights
Set cn = New ADODB.Connection
? -
Maitreya almost 5 yearsNo. It is highlights Dim cn As ADODB.Connection @Brad
-
Admin almost 5 yearsGo 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 almost 5 yearsThanks @Jeeped. It worked.
-
Gustav almost 5 yearsThen please mark as answered.
-