当前位置:网站首页>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:
边栏推荐
猜你喜欢

6 yuan per catty, why do Japanese companies come to China to collect cigarette butts?

防抖和节流有什么区别,分别用于什么场景?

OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.解决方法

【hbuilder】运行不了部分项目 , 打开终端 无法输入指令

中集世联达工业级成熟航运港口人工智能AI产品规模化应用,打造新一代高效能智慧港口和创新数字港口,全球港航人工智能能领军者中集飞瞳

MySql中@符号的使用

MindSpore:对image作normalize的目的是什么?

Talking about Contrastive Learning (Contrastive Learning) the first bullet

2种手绘风格效果比较,你更喜欢哪一种呢?

【MindSpore】多卡训练保存权重问题
随机推荐
Tensorflow2.0 混淆矩阵与打印准确率不符
延时队列优化 (2)
Scrapy框架介绍
Go system collection
又一家公司面试的内容
不同的路径依赖
Scala学习:类和对象
What is the difference between a cloud database and an on-premises database?
什么是 RESTful API?
【网站放大镜效果】两种方式实现
The advanced version of the Niu Ke brushing series (team competition, sorting subsequences, inverting strings, deleting common characters, repairing pastures)
几个GTest、GMock的例子
MindSpore:ImageFolderDataset数据读取问题
VS Code 连接SQL Server
[Use of Qt Designer tool]
Chapter 4 Controlling the Execution Flow
Recommendation | People who are kind to you, don't repay them by inviting them to eat
MindSpore:数据处理问题
LeetCode每日一题(1717. Maximum Score From Removing Substrings)
redis
