0
votes

I am trying to access a ms access table from a new excel vba workbook using DAO.database/DAO.recordset.

However, i am getting "unrecognised database format" in the opendatabase("path.accdb") line.

Dim a As DAO.Database
Dim b As DAO.Recordset
Set a = OpenDatabase("C:\Users\Sweety\Desktop\Database2.accdb")
Sql = "SELECT Name1,Age FROM Table2 "
Sql = Sql & "WHERE City = 'Berkeley' "
Set b = a.OpenRecordset(Sql)
Sheet1.Range("A1").CopyFromRecordset b
1
This is probably because you selected the wrong reference. You need to refer to something like "Microsoft Office 12.0 Access database engine Object Library"Storax
The DAO reference is generic, and should work with nearly any version of Access.kismert

1 Answers

0
votes

The usual fix is to do a Compact and Repair on the database C:\Users\Sweety\Desktop\Database2.accdb. Minor corruption issues happen quite often in Access back ends, and this will fix it (usually).

Notes:

  1. Check the Conversion Errors or MSysCompactErrors table afterwards to see if there were any unresolved corruption errors
  2. It is good to do this periodically as it shrinks the size of Access files