我有一个类正在处理我与 Access 2003 数据库的连接。我想仅为 Access 07/10 .accdb 文件设置相同的内容。任何帮助表示赞赏!谢谢!
这是我的引用列表和类对象的副本
参考:
- Microsoft Access 14.0 对象库
- Microsoft DAO 3.6 对象库
连接类:
Option Explicit
Private Const DbFile = "\\server\folders\Report.mdb"
Dim OpenConn As DAO.Database
Dim ObjAccess As Object
Private Sub Class_Initialize()
On Error Resume Next
Set OpenConn = DAO.OpenDatabase(DbFile)
If Err.Number = 3024 Then MsgBox "Check connection string in the VBA StaticClass object", vbOKOnly
Set ObjAccess = CreateObject("Access.Application")
ObjAccess.Visible = False
ObjAccess.OpenCurrentDatabase (DbFile)
End Sub
Public Function runSQL(ByVal sql As String) As Recordset
Set runSQL = OpenConn.OpenRecordset(sql)
End Function
Public Function runVolumeReport(ByVal inMacro As String)
ObjAccess.DoCmd.RunMacro inMacro
End Function
Public Function closeResources()
Set ObjAccess = Nothing
OpenConn.Close
End Function