I have a class that's handling my connection to an Access 2003 database. I would like to setup the same thing only for Access 07/10 .accdb files. Any help is appreciated! Thank you!
Here's a list of my references and a copy of the class object
References:
- Microsoft Access 14.0 Object Library
- Microsoft DAO 3.6 Object Library
ConnectionClass:
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

Dim OpenConn As Objectinstead ofDAO.Database. This allows for version independent code (but removes the cute popups you get when you type the.after OpenConn or DAO)