我希望能够编写一个以独占模式打开 Access 数据库的脚本,这样我就可以刷新其中的信息,而不必担心其他用户以不一致的状态 Access 数据库。有没有办法使用 VBA 或使用 VBScript 通过 COM 接口(interface)来执行此操作?
最佳答案
我不知道如果任何用户在脚本启动时打开数据库会发生什么。因此我选择检查数据库锁定文件是否存在,并且仅在锁定文件不存在时才继续。
这是 DoSomethingExclusively.vbs:
Option Explicit
Dim strFolder
Dim strMdb
Dim strLckFile
Dim objFSO
Dim appAccess
strFolder = "C:\Access\webforums\"
strMdb = "whiteboard2003.mdb"
strLckFile = "whiteboard2003.ldb"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not (objFSO.FileExists(strFolder & strLckFile)) Then
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase strFolder & strMdb, True
'* do something here; this just adds a row with current time *'
appAccess.CurrentDb.Execute _
"INSERT INTO foo (bar) VALUES ('" & CStr(Now()) & "');"
appAccess.Quit
Set appAccess = Nothing
End If
Set objFSO = Nothing
关于ms-access - 以独占模式打开Access数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5792169/