Error 3343: Unrecognized database format 'C:\Temp\Northwind.accdb"

I am tasked with connecting to an Access DB from a Word 2010 Macro.  I downloaded the Microsoft sample database and the sample verification code but that does not work either.  I can open the Access database so it does not appear to be corrupted.  Using the following VBA code it appears that I am able to find the database but not open it.

When I execute the following code I receive the Error 3343: Unrecognized database format 'C:\Temp\Northwind.accdb" on the line

                                                 Set dbNorthwind = OpenDatabase(Name:="C:\Temp\Northwind.accdb")

Since I am using Microsoft's sample Access DB and Sample code what am I doing wrong and how do I correct this issue. 

 

Thanks,

 

Sub UsingDAOWithWord()
 Dim docNew As Document
 Dim dbNorthwind As DAO.Database
 Dim rdShippers As Recordset
 Dim intRecords As Integer
 
 'Set docNew = Documents.Add
 Set dbNorthwind = OpenDatabase(Name:="C:\Temp\Northwind.accdb")
 Set rdShippers = dbNorthwind.OpenRecordset(Name:="Shippers")
 For intRecords = 0 To rdShippers.RecordCount - 1
 docNew.Content.InsertAfter Text:=rdShippers.Fields(1).Value
 rdShippers.MoveNext
 docNew.Content.InsertParagraphAfter
 Next intRecords
 rdShippers.Close
 dbNorthwind.Close
End Sub

Answer
Answer
Make sure you have made a reference to the correct DAO library (in VBA, in Tools->References). The old one, for .mdb files only, has DAO in its name. For .accdb files you need the new one, which is called "Microsoft Office 12.0 Access database engine Object Library" (or 14.0, for Office 10).

41 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Answer
Answer
I got the same error, but it seems the message is misleading. I found this article: http://support.microsoft.com/kb/209953. When I incorporated the DAO.Workspace object and the password in the OpenDatabase arguments from that article into the code you posted, it worked.

Sub UsingDAOWithWord()
 Dim docNew As Document
 Dim ws As DAO.Workspace
 Dim dbNorthwind As DAO.Database
 Dim rdShippers As Recordset
 Dim intRecords As Integer
 
 Set ws = DBEngine.Workspaces(0)
 Set docNew = Documents.Add
 Set dbNorthwind = ws.OpenDatabase("C:\Temp\Northwind.accdb", _
    False, False, "MS Access;PWD=northwind")

 Set rdShippers = dbNorthwind.OpenRecordset(Name:="Shippers")
 For intRecords = 0 To rdShippers.RecordCount - 1
 docNew.Content.InsertAfter Text:=rdShippers.Fields(1).Value
 rdShippers.MoveNext
 docNew.Content.InsertParagraphAfter
 Next intRecords
 rdShippers.Close
 dbNorthwind.Close
End Sub

I'm a Word guy, not so much an Access user, so I'm not sure what made OpenDatabase throw that particular error, or how you're supposed to find out about these requirements.
_____________________________
https://jay-freedman.info

14 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated February 21, 2024 Views 55,779 Applies to: