Tip

Remove Duplicate Address Book Documents

The user won't tell me how it happened, but between a botched import from a
WordPerfect mail merge file and a misfiring Palm Pilot he and his secretary
managed to duplicate most of the docs in his Personal Address Book. He now has
over 6000 docs. and at least 2500 are duplicates. I found Purna Sukhadia's
script here and modified it to brute-force delete any PAB doc with matching
first name, last name, company name, office phone number, mail address, and
business address. Ugly code and not very elegant in execution but easily
modified to suit your own purposes.

Copy and paste the code in your agent.
Sub Initialize
Dim s As New notessession
Dim db As notesdatabase
Dim doc1 As notesdocument
Dim doc2 As notesdocument
Dim view As notesview
Dim tempFirstName1 As Variant
Dim tempLastName1 As Variant
Dim tempOfficePhoneNumber1 As Variant
Dim tempCompanyName1 As Variant
Dim tempMailAddress1 As Variant
Dim tempBusinessAddress1 As Variant
Dim tempFirstName2 As Variant
Dim tempLastName2 As Variant
Dim tempOfficePhoneNumber2 As Variant
Dim tempCompanyName2 As Variant
Dim tempMailAddress2 As Variant
Dim tempBusinessAddress2 As Variant
Dim dupeCtr As Variant
Dim dc As NotesDocumentCollection

Set db=s.currentdatabase
Set dc = db.AllDocuments
Set doc1 = dc.GetFirstDocument()
Set doc2 = dc.GetFirstDocument()

tempFirstName1=""
tempLastName1=""
tempOfficePhoneNumber1=""
tempCompanyName1=""
tempMailAddress1=""
tempBusinessAddress1=""
tempFirstName2=""
tempLastName2=""
tempOfficePhoneNumber2=""
tempCompanyName2=""
tempMailAddress2=""
tempBusinessAddress2=""
dupeCtr=0

For j = 1 To dc.Count

For i = 1 To dc.Count
If (tempFirstName1=tempFirstName2) Then
If (tempLastName1=tempLastName2) Then
If (tempOfficePhoneNumber1=tempOfficePhoneNumber2) Then
If(tempCompanyName1=tempCompanyName2) Then
If (tempMailAddress1=tempMailAddress2) Then
If (tempBusinessAddress1=tempBusinessAddress2) Then
dupeCtr=dupeCtr+1
End If
End If
End If
End If
End If
End If

If dupeCtr>1 Then
Call doc2.remove(True)
dupeCtr=1
End If
Set doc2=dc.GetNthDocument(i)
tempFirstName2=doc2.FirstName(0)
tempLastName2=doc2.LastName(0)
tempOfficePhoneNumber2=doc2.OfficePhoneNumber(0)
tempCompanyName2=doc2.CompanyName(0)
tempMailAddress2=doc2.MailAddress(0)
tempBusinessAddress2=doc2.BusinessAddress(0)
Next
dupeCtr=0
Set doc1 = dc.GetNthDocument(j)
tempFirstName1=doc1.firstname(0)
tempLastName1=doc1.LastName(0)
tempOfficePhoneNumber1=doc1.OfficePhoneNumber(0)
tempCompanyName1=doc1.CompanyName(0)
tempMailAddress1=doc1.MailAddress(0)
tempBusinessAddress1=doc1.BusinessAddress(0)
Next
End Sub

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

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.