Domino Code Fragment

Code Name*
EKDOCLOC.LSS - Documentation and Sample Usage
Date*
04/19/2000
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.
Description*
EKDOCLOC.LSS - Documentation and Sample Usage
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
related notes: MSC Design Library, MSC Design Library

%REM
----------------------------------------------------------------------------
FILE:    EKDOCLOC.LSS - Documentation and Sample Usage
UPDATED: May 1997
AUTHOR:  Eric Koeler
       
mailto:ekoeler@panix.com
       
http://www.panix.com/~ekoeler
NOTE:    Copyright (C) 1997 by Eric Koeler, this file is protected by the
        GNU General Public License
----------------------------------------------------------------------------
The functions in the EKDOCLOC library are to be used for document edit-
locking.  This is a useful feature if you have many users who could
open and/or edit the same document simultaneously, which can lead to
replication/save conflicts.  


To implement document locking in a form module, call DocLockCreate() in the
QueryOpen event.  This will create an edit-lock name field with the current
user's name and an edit-lock time field with the current time.  If the doc
is already locked, the user will be prompted and told who currently has the
document open.  In the QueryModeChange event, call DocLockCheck(), which
will return True if the current user is locked out (the second parameter
to the function tells the function to prompt the user if they are locked
out).  In the QueryClose event, call DocLockRemove to remove the current
user's edit-lock; if the current user is locked out, this function doesn't
do anything.


You can simply import the sample the code below into a form module to
enable document locking.
----------------------------------------------------------------------------
%ENDREM


'Declarations
%INCLUDE "EKDOCLOC.LSS"


Sub Queryopen(Source   As Notesuidocument, _
             Mode     As Integer,         _
             Isnewdoc As Variant,         _
             Continue As Variant)
   
    On Error     Goto   ErrorHandler
    Dim sess     As New NotesSession
   
    '----- If this is a new doc, don't bother locking it
    If (Source.IsNewDoc) Then Goto TheEnd
   
    '----- If we can't create the doc lock, don't allow editing
    If Not(DocLockCreate(Source.Document)) Then


          '----- If we are opening directly in edit mode, cancel the open
         If Mode = 1 Then Continue = False
    End If
   
TheEnd:
    Exit Sub
   
ErrorHandler:
    Print Trim$(Str(Err)) & ": " & Error$
    Resume TheEnd
   
End Sub




Sub Querymodechange(Source As Notesuidocument, Continue As Variant)
   
    On Error Goto ErrorHandler
   
    '----- If we are trying to go into edit mode
    If Source.EditMode = False Then
                   
         '----- Check if the current user is locked out
         If DocLockCheck(Source.Document, True) Then Continue = False
    End If
   
TheEnd:
    Exit Sub
   
ErrorHandler:
    Print Trim$(Str(Err)) & ": " & Error
    Resume TheEnd
   
End Sub




Sub Queryclose(Source As Notesuidocument, Continue As Variant)
   
    On Error     Goto   ErrorTime
    Dim sess     As New NotesSession
    Dim temp     As     String
   
    '----- Remove the doc lock
    Call DocLockRemove(Source.Document)
         
TheEnd:
    Continue = True
    Exit Sub
   
ErrorTime:
    Print Trim$(Str$(Err)) & ": " & Error$
    Resume TheEnd
   
End Sub