把表达式 True=False 放到表的 ValidationRule 属性就能锁上。 HardLockTable?实现了该功能。
声明
Public MyDB As Database
Dim Dummy As Integer
函数
Function HardLockTable (ByVal whichAction As String,?ByVal aTable As String) As Integer
On Error GoTo HardLockTableError
HardLockTable = True
Select Case whichAction
Case "Lock"
MyDB.TableDefs(aTable).ValidationRule = "True=False"
MyDB.TableDefs(aTable).ValidationText =?"This table locked via " & ?"ValidationRule on " & Now
Case "UnLock"
MyDB.TableDefs(aTable).ValidationRule = ""
MyDB.TableDefs(aTable).ValidationText = ""
Case "TestThenUnLock"
If MyDB.TableDefs(aTable).ValidationRule = "True=False" Then
MyDB.TableDefs(aTable).ValidationRule = ""
MyDB.TableDefs(aTable).ValidationText = ""
End If
End Select
HardLockTableErrorExit:
'subFlushDBEngine
'optional, see next suggestion
Exit Function
HardLockTableError:
HardLockTable = False
MsgBox Error$ & " error " & "in HardLockTable trying " & "to " & whichAction & " " & aTable
Resume HardLockTableErrorExit
End Function
使用例子
'上锁
Dummy = HardLockTable("Lock", "TestTable")
' 开锁
Dummy = HardLockTable("UnLock", "TestTable")
文章来源于领测软件测试网 https://www.ltesting.net/
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073