| TITLE:  A generic function to check duplicate documents based on key field
 
 This tip was submitted by Teck Lung Ng, a consultant in Singapore.
 
 This is a generic function to check for any duplicate documents based
 on a lookup view and lookup key column.  It will handle both new and
 saved document checking.  The check on saved document is necessary, as
 the key in the document may be editable after it is saved.
 
 CODE:
 Function IsDocumentDuplicate (db As NotesDatabase, viewName As String, _
 keyColumnName As String, doc As NotesDocument, errorMsg As String)
 
 IsDocumentDuplicate = False
 
 Dim viewLookup As NotesView
 Dim docLookup As NotesDocument
 Dim errorString As String
 
 errorString = "Document already exists in the database!"
 Set viewLookup = db.GetView(viewName)
 If Not viewLookup Is Nothing Then
 Set docLookup = viewLookup.GetDocumentByKey(keyColumnName, True)
 If Not docLookup Is Nothing Then
 If doc.IsNewNote Then
 errorMsg = errorString
 Exit Function
 Else
 If doc.UniversalID <> docLookup.UniversalID Then
 errorMsg = errorString
 Exit Function
 End If
 End If
 Else
 errorMsg = "Error getting doc object for lookup document!"
 Exit Function
 End If
 Else
 errorMsg = "Error getting view object for lookup document!"
 Exit Function
 End If
 
 IsDocumentDuplicate = True
 
 End Function
 
 previous page
 
 
 |