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

【网站放大镜效果】两种方式实现

牛客刷题系列之进阶版(搜索旋转排序数组,链表内指定区间反转)

Golang logging library zerolog use record

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

Read the "Language Model" in one article

Basic use of scrapy

The advanced version of the Niu Ke brushing series (team competition, sorting subsequences, inverting strings, deleting common characters, repairing pastures)

Scrapy framework is introduced

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

AI Basics: Graphical Transformer
随机推荐
又一家公司面试的内容
【剑指 Offe】剑指 Offer 17. 打印从1到最大的n位数
2种手绘风格效果比较,你更喜欢哪一种呢?
VBA批量将Excel数据导入Access数据库
WEBSOCKETPP使用简介+demo
OneFlow source code analysis: Op, Kernel and interpreter
Scrapy框架介绍
Talking about Contrastive Learning (Contrastive Learning) the first bullet
vxe-table实现复选框鼠标拖动选中
延时队列优化 (2)
MindSpore:ImageFolderDataset数据读取问题
NXP IMX8QXP replacement DDR model operation process
MindSpore:【JupyterLab】按照新手教程训练时报错
AI Basics: Graphical Transformer
Delay queue optimization (2)
Scrapy framework is introduced
Correct pose of Vulkan open feature
Tensorflow2.0 混淆矩阵与打印准确率不符
MYSQL (Basic) - An article takes you into the wonderful world of MYSQL
【网站放大镜效果】两种方式实现
