title: Excel VBA Connection to Access 2010
body: <p>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!</p>
  
  <p>Here's a list of my references and a copy of the class object</p>
  
  <p>References:</p>
  
  <ul>
  <li>Microsoft Access 14.0 Object Library</li>
  <li>Microsoft DAO 3.6 Object Library</li>
  </ul>
  
  <p>ConnectionClass:</p>
  
  <pre><code>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
  </code></pre>