Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
858 views
in Technique[技术] by (71.8m points)

vba - 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.

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:Userse574651.GLOBALDocumentsNorthwind 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 Unrecognized database format 'C:Userse574651.GLOBALDocumentsNorthwind 2007.accdb'.

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"

How do I provide this functionality using DAO?

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.

Any assistance will be greatly appreciated.

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The most recent DAO libraries are in the format :

Microsoft Office x.x Access Database Engine Object Library

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:DocsTest.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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...