Home > Domino Tips > Administrator > Database > Prevent Duplicate Documents On Save
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

DATABASE

Prevent Duplicate Documents On Save


Brad Schauf
02.24.2000
Rating: -4.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Database
Quickly scan all databases on a Lotus Domino server
LotusScript code rebuilds corrupted busytime.nsf file
How to move Notes databases off Domino 8 servers and save disk space
Top 10 Lotus Notes/Domino administration tips of 2008
Batch file runs scheduled Lotus Notes database maintenance tasks
Fix and update Lotus Notes documents with limited access
Programmatically replace the design of Lotus Notes databases
Add a program doc to compact Lotus Notes databases automatically
More efficient local Lotus Notes database replication
Remove orphaned Lotus Notes documents on Domino databases with a 'virtual delete'

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts