CopyFromRecordset Automation Error

AlphonseG 236 Reputation points
2025-01-20T15:49:08.4033333+00:00

ExcelSheetPopulate.txtI had been running Office 2016 MSO (16.0.12624.20278) 32-bit for several years.

I've been using the attached code in MS Access for the past 5 years without any issue.

Suddenly, getting Error 430, 'Class does not support Automation or does not support expected interface', on line 470 CopyFromRecordset.

It runs fine on other machines using various versions of Office. I have been unable to resolve the error on my dev machine.

Repaired Office, both offline and online repairs.

Uninstalled (via the uninstall troubleshooter) and reinstalled to various versions, including the very latest.

Currently running 2019 MSO (Version 2208 Build 16.0.15601.20526) 32-bit.

Unregistered/re-registered both dao360.dll and msado15.dll.

Also ran DISM and sfc.

There are no missing references.

How can I resolve this error?

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
4,358 questions
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
901 questions
{count} votes

Accepted answer
  1. PCVXD 80 Reputation points
    2025-05-19T14:52:38.75+00:00

    I had to same issue but I was able to fix it while still using DAO! What I had to do was add a registry key. This article https://learn.microsoft.com/en-us/office/troubleshoot/access/running-wizard-error-loading-dll let me to that key.
    Be sure to back up your registry before you start, just in case. I will enclose keys and values in "" just so it's clear, but don't include those in the actual values.

    First close all Office applications. Check if you have key "Computer\HKEY_CLASSES_ROOT\TypeLib\{00025E01-0000-0000-C000-000000000046}\5.0\0\win32". You probably don't have it, so make it. Set the default value to "C:\Program Files (x86)\Common Files\Microsoft Shared\DAO\dao360.dll" or if you're running 64 bit Office I think it should be "C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll". Just check where that dll is located and choose that.

    Afterwards when you reopen Access, go to VBA and select Debug -> Compile, if I didn't do this it seemed to just crash instantly when running some VBA. Under Tools -> References you should now see an entry "Microsoft DAO 3.6 Object Library" pointing to the correct dll location we just set. You don't need to check/enable it if you're already using "Microsoft Office 16.0 Access database engine Object Library", it should just work now.

    Hope this fixed the problem like it did for me!

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Gustav 717 Reputation points MVP
    2025-01-20T17:57:54.15+00:00

    @Viorel It's the other way around; DAO has been the default, preferred, recommended, and most widely used engine since at least version 2007(!) where ACE were introduced.

    1 person found this answer helpful.
    0 comments No comments

  2. Sacherich, Ben 0 Reputation points
    2025-03-07T01:28:32.8366667+00:00

    A few minutes after my last post, I see that if I change the sample code to use an ADO recordset instead of DAO, the CopyFromRecordset command works fine using the same data. Go figure.

    I still want to find out why the DAO method has stopped working. I have too many legacy calls that worked fine with the DAO implementation. I don't want to just assume that all of my old queries will work with a switch to ADO.

    For example, I'm not sure if ADO handles user defined function calls in queries the same way as ADO. Same goes for Pivot queries, Unions, embedded references to on form controls, etc.

    Please don't try to convince me to "just switch to ADO because it works". I have dozens of applications that I'd have to change, and some where the source code is not longer around.
    We really want to know what changed in Windows/Office to cause this issue.

    
    Sub ExportToExcel_ADO()
        Dim cn As ADODB.Connection
        Dim rs As ADODB.Recordset
        Dim xlApp As Excel.Application
        Dim xlWorkbook As Excel.Workbook
        Dim xlWorksheet As Excel.Worksheet
        
        On Error GoTo ErrorHandler
        
        ' Initialize objects
        Set cn = CurrentProject.Connection
        Set rs = New ADODB.Recordset
        rs.Open "qryTest", cn, adOpenStatic, adLockReadOnly
        
        ' Create Excel application object
        Set xlApp = New Excel.Application
        xlApp.Visible = True
        
        ' Add new workbook and set reference to first sheet
        Set xlWorkbook = xlApp.Workbooks.Add()
        Set xlWorksheet = xlWorkbook.Worksheets(1)
        
        ' Copy headers from recordset
        Dim i As Integer
        For i = 0 To rs.Fields.count - 1
            xlWorksheet.Cells(1, i + 1).Value = rs.Fields(i).Name
        Next i
        
        ' Format headers
        With xlWorksheet.Range(xlWorksheet.Cells(1, 1), _
                              xlWorksheet.Cells(1, rs.Fields.count))
            .Font.Bold = True
            .Interior.ColorIndex = 6
            .HorizontalAlignment = -4108 'xlCenter
        End With
        
        ' Copy recordset data starting from row 2
        xlWorksheet.Range("A2").CopyFromRecordset rs ' <-- This line appears to work with an ADO recordset.
        
        ' Auto-fit columns
        xlWorksheet.UsedRange.Columns.AutoFit
        
        ' Clean up
        rs.Close
        Set rs = Nothing
        Set cn = Nothing
        
        Exit Sub
        
    ErrorHandler:
        Debug.Print Err.Number, Err.Description
        MsgBox Err.Description, vbCritical, "Error"
        On Error Resume Next
        rs.Close
        Set rs = Nothing
        Set cn = Nothing
    End Sub
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.