当前位置:网站首页>VBA runtime error '-2147217900 (80040e14): Automation error
VBA runtime error '-2147217900 (80040e14): Automation error
2022-07-30 19:10:00 【OOQ】
Problem description: When trying to use VBA to operate the Access database for the first time, when executing the INSERT operation, an exception of "runtime error '-2147217900 (80040e14): Automation (Automation) error" occurred.

Figure 1
Sub connect()Dim con As ADODB.Connection 'declare object variablesSet con = New ADODB.Connection 'Create object variableDim sql As String'Establish a database connection'con.Open "provider=microsoft.ace.oledb.12.0;data source=" & ThisWorkbook.Path & "\test.accdb" 'connect to the access database'The following is equivalent to con.OpenWith con.Provider = "microsoft.ace.oledb.12.0".ConnectionString = ThisWorkbook.Path & "\test.accdb".OpenEnd WithMsgBox "Connection succeeded"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 'Close the connectionSet con = Nothing 'Release the variableEnd SubSolution process:
1. Execute the following SQL in the Access SQL Query Analyzer, and the result is passed as shown in Figure 2.But VBA still doesn't pass
SQL insert into check(code,year,month,day) values ('1','2022','1','1')2. Consider whether it is caused by the use of fields such as code, year, month, day, etc., so change these fields to m_code, m_year, m_month, m_day.The problem still exists.
3. Check whether there are spaces before and after the field name
4. Referring to many cases, it is not necessary to add '' (single quotation marks) when the value is found to be a number.[The field type setting is short text type], the problem is solved.Successful as shown in Figure 3
sql = "insert into m_check(m_code,m_year,m_month,m_day) values (3,2022,1,1)"

Figure 2

Figure 3
Summary:
1. The database table field name cannot use keywords
2. Table fields cannot use spaces and other special characters
3. Eliminate SQL syntax errors
4. When the value is a number, single quotes should not be used, even if the table field type is a text type.
Reference:
边栏推荐
- DM8:单库单实例搭建本地数据守护服务
- 【剑指 Offe】剑指 Offer 18. 删除链表的节点
- DM8: Single database and single instance to build a local data guard service
- Object和Map的区别
- 运营 23 年,昔日“国内第一大电商网站”黄了...
- Critical Reviews | A review of the global distribution of antibiotics and resistance genes in farmland soil by Nannong Zou Jianwen's group
- [Use of Qt Designer tool]
- VBA 连接Access数据库和Excle
- Go 系统收集
- Range.CopyFromRecordset 方法 (Excel)
猜你喜欢

Scrapy框架介绍

Mysql execution principle analysis

NXP IMX8QXP replacement DDR model operation process

SwiftUI iOS Boutique Open Source Project Complete Baked Food Recipe App based on SQLite (tutorial including source code)

CIMC Shilian Dafeitong is the global industrial artificial intelligence AI leader, the world's top AI core technology, high generalization, high robustness, sparse sample continuous learning, industri

深入浅出边缘云 | 3. 资源配置

【剑指 Offer】剑指 Offer 22. 链表中倒数第k个节点

【剑指 Offe】剑指 Offer 17. 打印从1到最大的n位数

VBA批量将Excel数据导入Access数据库

OneFlow源码解析:Op、Kernel与解释器
随机推荐
Difference between Object and Map
【剑指 Offe】剑指 Offer 18. 删除链表的节点
自己需要努力
NXP IMX8QXP更换DDR型号操作流程
Scrapy framework is introduced
启动前台Activity
What is the value of biomedical papers? How to translate the papers into Chinese and English?
Basic use of scrapy
第14章 类型信息
Google's AlphaFold claims to have predicted almost every protein structure on Earth
在华为云,见证迷你世界的神奇觉醒
The large-scale application of artificial intelligence AI products in industrial-grade mature shipping ports of CIMC World Lianda will create a new generation of high-efficiency smart ports and innova
requet.getHeader("token") is null
【PHPWord】PHPOffice 套件之PHPWord快速入门
已删除
Delay queue optimization (2)
DM8:单库单实例搭建本地数据守护服务
【剑指 Offe】剑指 Offer 17. 打印从1到最大的n位数
中集世联达工业级成熟航运港口人工智能AI产品规模化应用,打造新一代高效能智慧港口和创新数字港口,全球港航人工智能能领军者中集飞瞳
【Prometheus】Prometheus联邦的一次优化记录[续]
