当前位置:网站首页>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 Sub
Solution 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:
边栏推荐
- Swiper轮播图片并播放背景音乐
- The use of terminal split screen tool Terminalx
- 中集世联达飞瞳全球工业人工智能AI领军者,全球顶尖AI核心技术高泛化性高鲁棒性稀疏样本持续学习,工业级高性能成熟AI产品规模应用
- Common linked list problems and their Go implementation
- 高并发秒杀项目总结
- Entering the applet for the first time
- Hello, my new name is "Bronze Lock/Tongsuo"
- 【科普】无线电波怎样传送信息?
- MindSpore:【Resolve node failed】解析节点失败的问题
- The use of @ symbol in MySql
猜你喜欢
【剑指 Offe】剑指 Offer 17. 打印从1到最大的n位数
6 yuan per catty, why do Japanese companies come to China to collect cigarette butts?
经济新闻:错误# 15:初始化libiomp5md。dll,但发现libiomp5md。已经初始化dll。解决方法
MindSpore:【MindSpore1.1】Mindspore安装后验证出现cudaSetDevice failed错误
[TypeScript]编译配置
C# wpf 无边框窗口添加阴影效果
VBA 连接Access数据库和Excle
SwiftUI iOS Boutique Open Source Project Complete Baked Food Recipe App based on SQLite (tutorial including source code)
scrapy基本使用
MindSpore:【Resolve node failed】解析节点失败的问题
随机推荐
Listen to the boot broadcast
VBA 连接Access数据库和Excle
【网站放大镜效果】两种方式实现
卫星电话是直接与卫星通信还是通过地面站?
MindSpore:ImageFolderDataset数据读取问题
Basic use of scrapy
VS Code 连接SQL Server
Critical Reviews | A review of the global distribution of antibiotics and resistance genes in farmland soil by Nannong Zou Jianwen's group
【剑指 Offe】剑指 Offer 18. 删除链表的节点
防抖和节流有什么区别,分别用于什么场景?
The advanced version of the Niu Ke brushing series (team competition, sorting subsequences, inverting strings, deleting common characters, repairing pastures)
- daily a LeetCode 】 【 191. A number of 1
MindSpore:Cifar10Dataset‘s num_workers=8, this value is not within the required range of [1, cpu_thr
Chapter 4 Controlling the Execution Flow
实体中增加操作方法
nlohmann json 使用指南【visual studio 2022】
云数据库和本地数据库有什么区别?
JS提升:Promise中reject与then之间的关系
JsonUtil基于字符串操作josn
golang日志库zerolog使用记录