
DATABASE
Prevent Duplicate Documents On Save
Brad Schauf 02.24.2000
Rating: -4.00- (out of 5)




This is a handy way I use to prevent users from saving duplicate documents. A duplicate document is defined by the document key, which is determined by your application. 1. Create a view of all documents, sorted by the key field or value of the key. Limit the view selection formula to those forms you wish to prevent duplicates for. 2. Create a field on the each form which evaluates to the key value. It should be a computed field. 3. Place the code for the Ok2Save function below in the Globals section of your form. This allows the function to be called anywhere within your form. 4. Place the following code fragment into the QuerySave event on each form which contains the key field: Continue = Ok2Save( source ). 5. In any buttons on your form which save the document, call Ok2Save( NotesUIDocument ) to determine if you can save the document. This will prevent documents from being saved if a document with the same key exists in the database. Enjoy! Function Ok2Save( source As NotesUIDocument ) As Variant Dim view As NotesView Dim db As NotesDatabase Dim doc As NotesDocument Dim s As New NotesSession Dim key As String Dim key2 As String Dim item As NotesItem ' get the current database and view Set db = s.CurrentDatabase Set view = db.GetView("(all)") ' this is the view created in step 1 above ' refresh document for validation formulas and get key for this document Call source.Refresh key = source.fieldgettext("key") ' check to see if the document key already exists.... Set doc = view.getdocumentbykey( key ) If doc Is Nothing Then ' first time saved Ok2Save = True Exit Function Else Set item = doc.GetFirstItem("key") key2 = item.values(0) If key2 = key Then ' key matched...possible duplicate" ' subsequent saves If doc.UniversalID = source.document.UniversalID Then 'saving same document 'unid matched, same doc, saving..." Ok2Save = True Exit Function Else ' duplicate document ' unid is different with same key...duplicate document" Messagebox "This would create a duplicate document. Save cancelled.",64,"Save" Ok2Save = False End If Else ' keys dont match not the same document 'keys dont match...saving" Ok2Save = True End If End If End Function
 |

|
Rate this Tip
|
To rate tips, you must be a member of SearchDomino.com. Register now
to start rating these tips. Log in if you are already a member.
|


');
// -->
DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.
|
 |
|
|
 |
|
 |