当前位置:网站首页>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:
边栏推荐
- 【总结】1396- 60+个 VSCode 插件,打造好用的编辑器
- Go system collection
- LocalDate时间生成
- MindSpore:Cifar10Dataset‘s num_workers=8, this value is not within the required range of [1, cpu_thr
- 高并发秒杀项目总结
- What is the difference between a cloud database and an on-premises database?
- 【刷题篇】计算质数
- 7.30模拟赛总结
- Spark学习:编译Spark项目时遇到的报错
- Tensorflow2.0 混淆矩阵与打印准确率不符
猜你喜欢
随机推荐
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.解决方法
经济新闻:错误# 15:初始化libiomp5md。dll,但发现libiomp5md。已经初始化dll。解决方法
The problem of writing go run in crontab does not execute
7.30模拟赛总结
还有三天忙完
VBA connects Access database and Excel
MindSpore:Cifar10Dataset‘s num_workers=8, this value is not within the required range of [1, cpu_thr
VBA批量将Excel数据导入Access数据库
牛客刷题系列之进阶版(搜索旋转排序数组,链表内指定区间反转)
跨域问题的解决方法
Node encapsulates a console progress bar plugin
Deepen school-enterprise cooperation and build an "overpass" for the growth of technical and skilled talents
深入浅出边缘云 | 3. 资源配置
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]
Swiper rotates pictures and plays background music
NXP IMX8QXP更换DDR型号操作流程
【MindSpore1.2.0-rc1产品】num_workers问题
golang日志库zerolog使用记录
AWS console