DAO.DBEngine类不再在使用Windows 10的MS Access 2016中注册 [英] DAO.DBEngine Class No Longer Registered in MS Access 2016 using Windows 10

查看:0
本文介绍了DAO.DBEngine类不再在使用Windows 10的MS Access 2016中注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个客户端最近从Windows 7升级到10,并从Access 2013升级到2016(包含在Office 365中)。

Excel中的VBA宏现在会生成以下错误:

运行时错误‘-2147221164(80040154)’类未注册。第:行

 Set myEngine = New DAO.DBEngine

我验证了DAO 3.6包含在参考资料中。有一个网站建议&修复Office安装,但我没有这样做。

response建议转向ADO,如果我能找到一些如何做到这一点的例子,我可能会愿意这样做。

相关代码如下:

Option Base 1
Sub importPLCDataFromAccess(monthToImport As Date)

'This sub imports Influent and Effluent Data from the Access Database PLC_Data.mdb
'   This database reads records from the PLC board on a daily basis and was created
'    using Automation Direct's PointOfView software for interfacing with PLC Boards

Dim myDbLocation As String
myDbLocation = "K:UsersWWTP ComputerDocumentsPOV_ProjectsPLC InterfacePLC_Data.mdb"

Dim myWorkbook As Workbook

'Skip spurious stuff ... 

Dim myEngine As DAO.DBEngine
Dim myDB As DAO.Database
Dim myRecordSet As DAO.Recordset
Dim myWorkSpace As DAO.Workspace

'Skip more spurious stuff ... 

Set myEngine = New DAO.DBEngine ' This is the offending line

Set myDB = myEngine.OpenDatabase(myDbLocation)

我似乎遗漏了一些基本的东西。如有任何帮助,我们不胜感激。

推荐答案

我建议使用后期绑定来实现代码的可移植性。一旦你让它工作,你就会发现它后来在另一台计算机上失败了。将所有内容声明为Object,然后使用CreateObject命令根据需要引入引用。

示例:

Public Function GetDBEngine() As Object  
    On Error Resume Next
    
    'try 120
    Set GetDBEngine = CreateObject("DAO.DBEngine.120")
    
    If Err.Number <> 0 Then
        'try 36
        Err.Clear
        Set GetDBEngine = CreateObject("DAO.DBEngine.36")
        If Err.Number <> 0 Then         
            Set GetDBEngine = CreateObject("DAO.DBEngine.35")  
            Err.Clear         
        End If        
    End If

    On Error Goto 0
End Function



Sub importPLCDataFromAccess(monthToImport As Date)
    'This sub imports Influent and Effluent Data from the Access Database PLC_Data.mdb
    '   This database reads records from the PLC board on a daily basis and was created
    '    using Automation Direct's PointOfView software for interfacing with PLC Boards

    Dim myDbLocation As String
    myDbLocation = "K:UsersWWTP ComputerDocumentsPOV_ProjectsPLC InterfacePLC_Data.mdb"
    
    Dim myWorkbook As Workbook
    
    'Skip spurious stuff ...
    
    Dim myEngine As Object
    Dim myDB As Object
    Dim myRecordSet As Object
    Dim myWorkSpace As Object
    
    'Skip more spurious stuff ...
    
    Set myEngine = GetDBEngine
    
    Set myDB = myEngine.OpenDatabase(myDbLocation)
    

脚注:

既然我们在这里,我能说服您放弃Option Base 1吗?当然,还有其他方法可以让您的代码从1开始,而不违反时空连续体。

这篇关于DAO.DBEngine类不再在使用Windows 10的MS Access 2016中注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆