尝试使用DAO从外部Access(Outlook / Excel)连接到有效数据库会生成3343无法识别的数据库格式错误 [英] Attempt to connect to a valid database from outside Access (Outlook/Excel) using DAO generates a 3343 unrecognized database format error
问题描述
感谢您的网站。精彩的信息。
Thanks for your site. Wonderful information.
简而言之,我试图从Outlook(2007)执行以下代码,尽管它在Excel中也失败。
In a nutshell, I'm trying to execute the following code from Outlook (2007), although it fails in Excel as well. Works great INSIDE Access!
Sub Test
Dim db As DAO.Database
Dim rs As DAO.Recordset
Const dbPath As String = "C:\Users\e574651.GLOBAL\Documents\Northwind 2007.accdb"
On Error Resume Next
Set db = DAO.OpenDatabase(dbPath)
'Set rs = db.OpenRecordset("customers")
Debug.Print Err.Number, Err.Description
End Sub
3343无法识别的数据库格式'C:\Users\e574651。 GLOBAL\Documents\Northwind 2007.accdb'。
我可以整天使用ADO访问(无双关语)这个数据库,我怀疑问题在于以下ADO语句:
I can access (no pun intended) this database all day long using ADO, and I suspect the problem lies with the following ADO statement:
ADOConn.Provider = Microsoft.ACE.OLEDB.12.0
ADOConn.Provider = "Microsoft.ACE.OLEDB.12.0"
如何使用DAO提供此功能?
How do I provide this functionality using DAO?
我在VBA首选项中包含了对DAO 3.6库的引用。我已经包括了其他Microsoft 12.0库引用,所以我要么弄糟了什么,要么省略了一些东西。
I have included a reference to the DAO 3.6 library in my VBA preferences. I've included the other Microsoft 12.0 library references, so I've either clobbered something or omitted something.
任何帮助将不胜感激。
谢谢!
推荐答案
最新的DAO库的格式为:
The most recent DAO libraries are in the format :
Microsoft Office x.x Access Database Engine Object Library
因此,请摆脱3.6参考并使用更新的库。然后,举一个例子:
So get rid of the 3.6 reference and use a more recent library. Then, an example:
Sub XLAccess()
Dim ws As DAO.Workspace
Dim db As DAO.Database
Dim sDb As String
Dim sSQL As String
Dim qdf As QueryDef
sDb = "Z:\Docs\Test.accdb"
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(sDb)
''A stored query would be better
sSQL = "Parameters p1 Text, p2 Datetime; " _
& "INSERT INTO Table1 (AText,ADate) Values ([p1],[p2])"
Set qdf = db.CreateQueryDef("", sSQL)
qdf.Parameters!p1 = "ABC"
qdf.Parameters!p2 = #1/17/2013#
qdf.Execute dbFailOnError
Debug.Print qdf.RecordsAffected
End Sub
这篇关于尝试使用DAO从外部Access(Outlook / Excel)连接到有效数据库会生成3343无法识别的数据库格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!