ADODB连接和ADODB.Recordset-未定义用户定义类型 [英] ADODB.Connection & ADODB.Recordset - User define type not defined

查看:796
本文介绍了ADODB连接和ADODB.Recordset-未定义用户定义类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用VBA连接Access DB时遇到一个奇怪的错误. VBA代码如下所示:

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

有人可以帮助我,为什么它不接受ADODB以及如何解决这个问题?

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

推荐答案

转到VBE的工具,然后在引用"中找到并在"Microsoft ActiveX数据对象6.1库"旁边打勾,以将该库包含在您的项目中.

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.

这篇关于ADODB连接和ADODB.Recordset-未定义用户定义类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆