How to repair office DAO? (Or is it my fault excel crashes?)

1

I did following: A database connection over vba in excel (DAO) works both in office 356 and 2016. After setting a database password in Office 356 this db cannot be opened over DAO in Office 2016. (both same lib, Office Access 16 database engine object". So I set the password in Office 16, works now. After opening the file in Excel 356 again Excel crashes at an unexpected operation without error message. Now all other DAO connections in all files on this pc do not work anymore. (I think its just a random bug and hasn't anything to do with this password thing)

This error is actually reproducible on this pc.

  1. I created a test.accdb and added one table with 2 fields and one record.
  2. I created a test.xlsm and added following code:
Sub Test()
    Dim db As DAO.Database
    Set db = DAO.OpenDatabase(ActiveWorkbook.Path & "/test.accdb")
    Dim ts As DAO.Recordset
    Set ts = db.OpenRecordset("SELECT * FROM Tabelle1")
    Dim myfield As DAO.field
    If Not ts.EOF Then
        For Each myfield In ts.Fields ' crash here
            MsgBox myfield.Name
        Next
    End If
    ts.Close
    db.Close
End Sub

enter image description here

At exactly this line excel stops existing. Just press F8(next line) and back to desktop. Just away. No error. ts.Fields is not nothing as you can see in image. I've restarted my system, no change. How to repair DAO database connections? Or is some problem in this code? The same files work like expected on my other pc.

EDIT: As noted correclty it is not wise to call the object "field" as Excel imports the namespace of DAO automatically. The error also occurs when naming it myfield.

EDIT2: The error found in system protocol is somehow unspecific: ACEDAO.DLL 0xc0000005

excel
vba
dao
asked on Stack Overflow Dec 1, 2020 by SalkinD • edited Dec 1, 2020 by SalkinD

1 Answer

0

Thanks for your help. It was an MS Office error which was resolved after office reinstall.

answered on Stack Overflow Dec 2, 2020 by SalkinD

User contributions licensed under CC BY-SA 3.0