当前位置:网站首页>VBA 运行时错误‘-2147217900(80040e14):自动化(Automation)错误
VBA 运行时错误‘-2147217900(80040e14):自动化(Automation)错误
2022-07-30 18:50:00 【OOQ】
问题描述:初次尝试使用VBA去操作Access数据库,执行 INSERT 操作的时候,发生了“运行时错误'-2147217900(80040e14):自动化(Automation)错误”异常。
图 1
Sub 连接()
Dim con As ADODB.Connection '声明对象变量
Set con = New ADODB.Connection '创建对象变量
Dim sql As String
'建立数据库连接
'con.Open "provider=microsoft.ace.oledb.12.0;data source =" & ThisWorkbook.Path & "\test.accdb" '连接access数据库
'以下写法等效于 con.Open
With con
.Provider = "microsoft.ace.oledb.12.0"
.ConnectionString = ThisWorkbook.Path & "\test.accdb"
.Open
End With
MsgBox "连接成功"
sql = "insert into check(code,year,month,day) values ('1','2022','1','1')"
'sql = "insert into m_check(m_code,m_year,m_month,m_day) values (3,2022,1,1)"
con.Execute (sql)
con.Close '关闭连接
Set con = Nothing '释放变量
End Sub
解决过程:
1.在Access SQL 查询分析器执行以下SQL,结果类似如图2所示是通过的。但是VBA运行仍然不通过
SQL insert into check(code,year,month,day) values ('1','2022','1','1')2.考虑是不是因为使用了 code 、year 、month 、day 等字段所引起的,所以将这几个字段更改成了 m_code、m_year、m_month、m_day。问题还是存在。
3.检查字段名前后有无空格
4.参考许多案例,发现值是为数字的时候,不需要加 ''(单引号)。【字段类型设置是短文本类型】,问题解决。如图3成功
sql = "insert into m_check(m_code,m_year,m_month,m_day) values (3,2022,1,1)"

图 2

图 3
总结:
1. 数据库表字段名称不能使用关键字
2.表字段不能使用空格和其他特殊字符
3.排除SQL语法错误
4.值为数字时,不应使用单引号,即使表字段类型是文本类型。
参考:
边栏推荐
- OneFlow source code analysis: Op, Kernel and interpreter
- OneFlow源码解析:Op、Kernel与解释器
- 常见链表题及其 Go 实现
- MySQL data types
- Immersive experience iFLYTEK 2022 Consumer Expo "Official Designated Product"
- Node encapsulates a console progress bar plugin
- 荐号 | 对你有恩的人,不要请吃饭来报答
- Anaconda Navigator卡在loading applications
- arcpy获取要素类(属性表)包含的数目
- MySQL数据类型
猜你喜欢

电脑死机的时候,发生了什么?

NC | 西湖大学陶亮组-TMPRSS2“助攻”病毒感染并介导索氏梭菌出血毒素的宿主入侵...

卫星电话是直接与卫星通信还是通过地面站?

延时队列优化 (2)

Fixed asset visualization intelligent management system

Swiper轮播图片并播放背景音乐

OneFlow源码解析:Op、Kernel与解释器

微博广告分布式配置中心的构建与实践(有彩蛋)

Does the satellite phone communicate directly with the satellite or through a ground station?

Scrapy框架介绍
随机推荐
Swiper轮播图片并播放背景音乐
第4章 控制执行流程
NC | Tao Liang Group of West Lake University - TMPRSS2 "assists" virus infection and mediates the host invasion of Clostridium sothrix hemorrhagic toxin...
[Use of Qt Designer tool]
OSPF详解(4)
Mongo for infrastructure
经济新闻:错误# 15:初始化libiomp5md。dll,但发现libiomp5md。已经初始化dll。解决方法
Deepen school-enterprise cooperation and build an "overpass" for the growth of technical and skilled talents
432.4 FPS 快STDC 2.84倍 | LPS-Net 结合内存、FLOPs、CUDA实现超快语义分割模型
Pytorch foundation -- tensorboard use (1)
7.29模拟赛总结
DM8: Single database and single instance to build a local data guard service
Basic use of scrapy
mysql的多实例
线性筛求积性函数
单例模式 (Singleton)
你好,我的新名字叫“铜锁/Tongsuo”
ByteArrayInputStream class source code analysis
积性函数
生物医学论文有何价值 论文中译英怎样翻译效果好
