Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Sub Click(Source As Button)

Dim db As New NotesDatabase( "", "names.nsf" )


Dim view As NotesView
Dim doc1 As NotesDocument
Dim doc2 As NotesDocument
Dim targ As String 'Email address to search for
Dim add As String 'Contact email address
Dim nam As String 'Contact full name
Dim resp As Integer 'User response to prompt
Dim cnt1 As Integer 'Counter for matches
Dim cnt2 As Integer 'Counter for deletions

'Add the email address to search on here:
targ = "BBO Arkiv"

cnt1 = 0
cnt2 = 0

Set view = db.GetView( "RecentCollaborators" )

Set doc1 = view.GetFirstDocument
Messagebox "This will scan your Recent Contacts list for addresses that are no
longer valid.",, "Begin"

While Not(doc1 Is Nothing)
'Selects the value of the MailAddress field of the contact document to compare w
ith email address
'This line can be modified to compare other fields in the document with the sea
rch criteria
add = doc1.GetItemValue("MailAddress")(0)

If add = targ Then
cnt1 = cnt1 + 1
nam = doc1.GetItemValue("FullName")(0)

'If match found in Recent Contacts, ask user if they want to delete the entry
resp = Messagebox("Found entry for " & nam & " in your Recent Contacts list wit
h the wrong email address. Delete this entry?", 4 + 32 + 256, "Delete?")
Set doc2 = view.GetNextDocument(doc1)
If resp = 6 Then

'Error if user has the contact document open
If doc1.IsUIDocOpen Then
Messagebox "The entry for " & nam & " is open in your Recent Contacts list. Ple
ase close the entry and try the operation again.", 16, "Error!"
Else
doc1.RemovePermanently(True)
cnt2 = cnt2 + 1
Messagebox "The entry for " & nam & " was deleted.", 48, "Deleted!"
End If
Else
Messagebox "The entry for " & nam & " was not deleted.", 48, "Not Deleted!"
End If
Set doc1 = doc2
Else
Set doc1 = view.GetNextDocument(doc1)
End If
Wend

If cnt1 = 0 Then
Messagebox "Scan completed. No matches found.",, "Completed"
Else
Messagebox "Scan completed. " & cnt1 & " matches found, " & cnt2 & " contacts d
eleted.",, "Completed"
End If
End Sub

You might also like