**** 在资料库中建立以下设计元件
1. Create New Form. ( FormName = FrmLock)
2. Create a New View , ViewName = DocLock , And Sort By DocNo (Desending)
**** 以下在要作文件锁定控制之表单上增加
1 . 在表单 Global Declaration 中宣告以下变数
Dim LockFlag As Integer ‘ 表示正由自己或别人锁定中
Dim LockByMe As Integer ‘ 表示正由自己锁定中 , 在QueryClose 时清除
Dim LockTime As Variant ‘ 储存锁定文件之时间 , 於 PostOpen 时取得
2. 在 Form. PostOpen Event 中加入下段程式 (取得文件开启当时, 锁定文件之最后异动时间)
**** 在资料库中建立以下设计元件
1. Create New Form. ( FormName = FrmLock)
2. Create a New View , ViewName = DocLock , And Sort By DocNo (Desending)
**** 以下在要作文件锁定控制之表单上增加
1 . 在表单 Global Declaration 中宣告以下变数
Dim LockFlag As Integer ‘ 表示正由自己或别人锁定中
Dim LockByMe As Integer ‘ 表示正由自己锁定中 , 在QueryClose 时清除
Dim LockTime As Variant ‘ 储存锁定文件之时间 , 於 PostOpen 时取得
2. 在 Form. PostOpen Event 中加入下段程式 (取得文件开启当时, 锁定文件之最后异动时间)
Dim sn As New NotesSession
Dim db As NotesDatabase
Dim View As NotesView
Dim Doc As NotesDocument
Dim Sno As String
Dim UName As String
‘//取得现用资料库
SNo = Source.Document.SNo(0)
Set db = sn.CurrentDatabase
Set View = Db.GetView(“DocLock”)
UName = sn.CommonUserName
‘//取得锁定文件,如果文件不存在, 则重新建立新的锁定文件
Set Doc = View.GetDocumentByKey(SNo)
If Doc Is Nothing Then
Set Doc = db.CreateDocument
Doc.Form. = “frmLock”
Doc.DocNo = SNo
Doc.Locker = UName
Doc.AppendItemValue “$PublicAccess”, “1〃
Doc.LockTime = Now()
Doc.Save True, True
LockFlag = True
LockByMe = True
End If
LockTime = Doc.LastModified
3. 在 Form. QueryModeChange Event 中加入下段程式 (取得文件开启当时 , 锁定文件之最后异动时间)
Dim sn As New NotesSession
Dim db As NotesDatabase
Dim View As NotesView
Dim Doc As NotesDocument
Dim Sno As String
Dim strMsg As String
Dim UName As String
Dim NewLockTime As Variant
‘//SNo 是笔者设定的文件编号栏位, 用来作为识别锁定文件的 Key 值, 各位可以斟酌参考运用
SNo = Source.Document.SNo(0)
‘//取得现用资料库
Set db = sn.CurrentDatabase
Set View = Db.GetView(“DocLock”)
Set Doc = View.GetDocumentByKey(SNo)
UName = sn.CommonUserName
‘//取得锁定文件之最后异动时间
NewLockTime = Doc.LastModified
If NewLockTime LockTime Then
Msgbox “文件已被其他人员修改过 , 请离开重新进入” , 16 , “讯息”
Continue = False
Exit Sub
End If
‘//判断文件是否存在或被自己锁定中
If (Doc.Locker(0) = “”) Or (Doc.Locker(0) = UName) Then
Doc.Locker = UName
Doc.LocTime = Now()
Doc.Save True , True
LockFlag = True
LockByMe = True
Continue =True
Else
strMsg = “此文件正被 ” + Doc.Locker(0) + ” 编辑中 !”
Msgbox strMsg , 16 , “讯息”
LockFlag = True
LockByMe = False
Continue =False
End If
4. 在 Form. QueryClose Event 中加入下段程式 (清除自己锁定之资料)
Dim sn As New NotesSession
Dim db As NotesDatabase
Dim View As NotesView
Dim Doc As NotesDocument
Dim Sno As String
Dim strMsg As String
‘//取得现用资料库
SNo = Source.Document.SNo(0)
Set db = sn.CurrentDatabase
Set View = Db.GetView(“DocLock”)
Set Doc = View.GetDocumentByKey(SNo)
‘//被自己锁定中 , 清除
If LockByMe = True Then
Doc.Locker = “”
Doc.Save True , True
Continue =True
End If
—–