Attempt to connect to a valid database from outside Access (Outlook/Excel) using DAO generates a 3343 unrecognized database format error

左心房为你撑大大i 提交于 2019-11-29 11:06:34

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:\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

Use a more recent version or the latest access database on your references.

For example: Inside your Visual Basics Window = Go to Tools > References > Microsoft Office 14.0 Access Database Engine Object Library.

Then use the following to open your database:

Dim database_data As DAO.Database
Dim rsData As DAO.Recordset
Dim field_index As Integer

Set database_data = DAO.OpenDatabase("demo1.accdb")

At times, it might be necessary too type out the full path to your database file, e.g. "C:\User\Documents\projects\demo1.accdb"

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!