使用Office 2007在Visual Basic上创建“Access.Application”对象时出错(Error creating “ Access.Application” Object o

编程入门 行业动态 更新时间:2024-10-25 12:25:38
使用Office 2007在Visual Basic上创建“Access.Application”对象时出错(Error creating “ Access.Application” Object on Visual Basic with Office 2007)

我创建了一个应用程序,它接受一个Excel文件并将其插入到我的访问数据库表中。 我在计算机中使用了Microsoft Access 15.0对象库。 但当我在另一台使用Access 2007的计算机上执行应用程序时,它会立即停止。 这是代码:

Private Sub xlsTomdb() On Error GoTo err_handler Dim oAccess As Access.Application Set oAccess = CreateObject("Access.Application") oAccess.Visible = False oAccess.OpenCurrentDatabase App.Path + "\archivi.mdb", True oAccess.DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "EXCEL", App.Path + "\Export\Final.xls", True oAccess.Quit err_handler: MsgBox "The code failed at line " & Erl, vbCritical End Sub

msgBox显示“代码作为第0行失败”。 当我删除错误处理程序时,程序继续正常执行。 在使用Office 2007的另一台PC上运行该程序时,它终止于此功能,运行时出现错误[-2147467259(80004005)microsoft odbc microsoft access driver type mismatch in expression]

此功能在按钮单击事件上执行。 有没有理由不开放访问2007,因为我在构建它时使用了Access 2013?

有人可以帮忙吗?

I have created a application that takes an Excel file and inserts it into my access database table. I used Microsoft Access 15.0 Object Library in my computer . But when I executed the application it in an another computer with Access 2007 it stops immediately. This is the code:

Private Sub xlsTomdb() On Error GoTo err_handler Dim oAccess As Access.Application Set oAccess = CreateObject("Access.Application") oAccess.Visible = False oAccess.OpenCurrentDatabase App.Path + "\archivi.mdb", True oAccess.DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "EXCEL", App.Path + "\Export\Final.xls", True oAccess.Quit err_handler: MsgBox "The code failed at line " & Erl, vbCritical End Sub

The msgBox shows "The code failed as line 0". When I removed the Error Handler the program continues the execution normally. While running the program on another PC with Office 2007 it terminates at this function with runtime error [-2147467259 (80004005) microsoft odbc microsoft access driver type mismatch in expression]

This function is executed on button click event. Is there any reason not to open access 2007, because I used Access 2013 while building it?

Can anyone help?

最满意答案

EBalla:

“Microsoft Access 15.0对象”或DAO 15库属于Office 2013.早期版本不会了解此库。 如果您的目标计算机使用的是Office 2007,则需要在项目中添加引用“Microsoft Access 12.0对象库”。 您遇到兼容性问题而不是代码问题。

另请查看: http : //allenbrowne.com/ser-38.html

EBalla:

"Microsoft Access 15.0 Object" or DAO 15 library belongs to office 2013. Earlier versions will not know about this library. if your target machines are using office 2007 you need to add the reference "Microsoft Access 12.0 Object library" into your project. You are experiencing compatibility issue rather than code issue.

also check this out: http://allenbrowne.com/ser-38.html

更多推荐

本文发布于:2023-08-07 12:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464207.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   Basic   Visual   Office   Access

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!