我构建了一个宏来将 Excel 工作表中的数据附加到共享的 Access 数据库 (Access 2010)。
当宏运行时,它会提取单元格值并将其作为单行附加到 Access 表中。我已经对其进行了多次测试,它在附加数据方面做得很好。
当宏完成运行时,问题就来了。如果我单击数据库,它会立即锁定并且不会让我打开数据库。解决这个问题的唯一方法是进入 VBA 并点击重置按钮。由于某种原因,这会解锁数据库。
我进入 Access 数据库并将选项 > 客户端设置设置为无锁。
任何想法如何阻止它锁定?为什么close方法不关闭连接并释放数据库?
Dim Db As Database
Dim Rs As Recordset
Dim ws As DAO.Workspace
Dim Path As String
Path = "X:\EKTT-Log.accdb"
Set ws = DBEngine.Workspaces(0)
Set Db = ws.OpenDatabase(Path, _
False, False, "MS Access;") ' Learn more http://msdn.microsoft.com/en-us/library/office/ff835343.aspx
Set Rs = Db.OpenRecordset("Results Log", dbOpenTable, dbAppendOnly, dbPessimistic) ' Learn more http://msdn.microsoft.com/en-us/library/office/ff820966(v=office.14).aspx
' Log At a Glance
If Sheets(">>>>").Cells(15, "G") <> "" Then
Rs.AddNew
Rs.Fields("CTYHOCN") = CTYHOCN
Rs.Fields("eCommerce Manager") = eComMgr
Rs.Fields("Timestamp Start") = TimeStart
Rs.Fields("Timestamp Finish") = TimeFinish
Rs.Fields("Global Web Page") = Sheets(">>>>").Cells(15, "B")
Rs.Fields("Keyword Target") = Sheets(">>>>").Cells(15, "G")
Rs.Fields("Est Search Vol") = Sheets(">>>>").Cells(15, "H")
Rs.Fields("Title Tag") = Sheets(">>>>").Cells(15, "C")
Rs.Fields("Meta Description") = Sheets(">>>>").Cells(15, "E")
Rs.Update
Else
'
End If
' Close database & resume screenupdating
Rs.Close
Db.Close
ws.Close
Set Rs = Nothing
Set Db = Nothing
Set ws = Nothing
Application.ScreenUpdating = True