锁住数据库中的表
今天图老师小编要跟大家分享锁住数据库中的表,精心挑选的过程简单易学,喜欢的朋友一起来学习吧!
声明
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")->