当前位置:网站首页>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.值为数字时,不应使用单引号,即使表字段类型是文本类型。
参考:
边栏推荐
- CCNA-子网划分(VLSM)
- C# wpf 无边框窗口添加阴影效果
- requet.getHeader(“token“) 为null
- Mysql execution principle analysis
- kotlin by lazy
- The use of terminal split screen tool Terminalx
- 中集世联达飞瞳全球工业人工智能AI领军者,全球顶尖AI核心技术高泛化性高鲁棒性稀疏样本持续学习,工业级高性能成熟AI产品规模应用
- Delay queue optimization (2)
- The Meta metaverse division lost 2.8 billion in the second quarter!Still want to keep betting?Metaverse development has yet to see a way out!
- core sound driver详解
猜你喜欢

CCNA-子网划分(VLSM)

Pytorch基础--tensorboard使用(一)

Basic use of scrapy

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

The Meta metaverse division lost 2.8 billion in the second quarter!Still want to keep betting?Metaverse development has yet to see a way out!

ESP8266-Arduino programming example-HC-SR04 ultrasonic sensor driver

载誉而归,重磅发布!润和软件亮相2022开放原子全球开源峰会
![【Prometheus】Prometheus联邦的一次优化记录[续]](/img/5d/56e171b7a02584337a0cfe5c731fb2.png)
【Prometheus】Prometheus联邦的一次优化记录[续]

WeChat Mini Program Cloud Development | Urban Information Management

SwiftUI iOS Boutique Open Source Project Complete Baked Food Recipe App based on SQLite (tutorial including source code)
随机推荐
基于b/s架构搭建一个支持多路摄像头的实时处理系统 ---- 使用yolo v5 系列模型
【每日一道LeetCode】——191. 位1的个数
防抖和节流有什么区别,分别用于什么场景?
kotlin的by lazy
Critical Reviews | A review of the global distribution of antibiotics and resistance genes in farmland soil by Nannong Zou Jianwen's group
while,do while,for循环语句
OSPF详解(3)
设计消息队列存储消息数据的 MySQL 表格
智慧中控屏
沉浸式体验科大讯飞2022消博会“官方指定产品”
Read the "Language Model" in one article
【剑指 Offe】剑指 Offer 17. 打印从1到最大的n位数
CCNA-子网划分(VLSM)
深化校企合作 搭建技术技能人才成长“立交桥”
几个GTest、GMock的例子
WEBSOCKETPP使用简介+demo
OneFlow source code analysis: Op, Kernel and interpreter
【Prometheus】Prometheus联邦的一次优化记录[续]
Network Basics (3) 01-Basic Concepts of Networks - Protocols, Host Addresses, Paths and Parameters of URL Addresses & 127.0.0.1 Local Loopback Address & View URL IP Address and Access Ping Space + URL
第14章 类型信息
