把表達式True=False放到表的ValidationRule屬性就能鎖上。HardLockTable?實現了該功能。
聲明
PublicMyDBAsDatabase
DimDummyAsInteger
函數
FunctionHardLockTable(ByValwhichActionAsString,?ByValaTableAsString)AsInteger
OnErrorGoToHardLockTableError
HardLockTable=True
SelectCasewhichAction
Case"Lock"
MyDB.TableDefs(aTable).ValidationRule="True=False"
MyDB.TableDefs(aTable).ValidationText=?"Thistablelockedvia"&?"ValidationRuleon"&Now
Case"UnLock"
MyDB.TableDefs(aTable).ValidationRule=""
MyDB.TableDefs(aTable).ValidationText=""
Case"TestThenUnLock"
IfMyDB.TableDefs(aTable).ValidationRule="True=False"Then
MyDB.TableDefs(aTable).ValidationRule=""
MyDB.TableDefs(aTable).ValidationText=""
EndIf
EndSelect
HardLockTableErrorExit:
'subFlushDBEngine
'optional,seenextsuggestion
ExitFunction
HardLockTableError:
HardLockTable=False
MsgBoxError$&"error"&"inHardLockTabletrying"&"to"&whichAction&""&aTable
ResumeHardLockTableErrorExit
EndFunction
使用例子
'上鎖
Dummy=HardLockTable("Lock","TestTable")
'開鎖
Dummy=HardLockTable("UnLock","TestTable")->