当前位置:网站首页>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:
边栏推荐
- 跨域问题的解决方法
- 高并发秒杀项目总结
- Witness the magical awakening of the mini world in HUAWEI CLOUD
- 【PHPWord】PHPOffice 套件之PHPWord快速入门
- 7.29模拟赛总结
- Spark学习:用spark实现ETL
- 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!
- Listen to the boot broadcast
- VBA 连接Access数据库和Excle
- C# wpf 无边框窗口添加阴影效果
猜你喜欢
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
基于inquirer封装一个控制台文件选择器
卫星电话是直接与卫星通信还是通过地面站?
阿里云武林头条活动分享
VBA批量将Excel数据导入Access数据库
Recommendation | People who are kind to you, don't repay them by inviting them to eat
golang日志库zerolog使用记录
MongoDB打破了原则引入SQL?
AI Basics: Graphical Transformer
Spark学习:用spark实现ETL
随机推荐
natural language processing nltk
MindSpore:【模型训练】【mindinsight】timeline的时间和实际用时相差很远
【剑指 Offe】剑指 Offer 17. 打印从1到最大的n位数
Swiper轮播图片并播放背景音乐
Spark学习:编译Spark项目时遇到的报错
DM8: Single database and single instance to build a local data guard service
中集世联达飞瞳全球工业人工智能AI领军者,全球顶尖AI核心技术高泛化性高鲁棒性稀疏样本持续学习,工业级高性能成熟AI产品规模应用
高并发秒杀项目总结
Range.CopyFromRecordset 方法 (Excel)
【科普】无线电波怎样传送信息?
Go system collection
阿里云武林头条活动分享
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.解决方法
Vulkan开启特征(feature)的正确姿势
Recommendation | People who are kind to you, don't repay them by inviting them to eat
【hbuilder】运行不了部分项目 , 打开终端 无法输入指令
AI基础:图解Transformer
7.29模拟赛总结
What is the difference between a cloud database and an on-premises database?
Chapter 14 Type Information