Update a field in all Lotus Notes documents using a Lotus Notes agent

SearchDomino.com member Mick Crowder provides a Lotus Notes agent that will allow you to update a specific field in all selected Lotus Notes documents with new data.


With this Lotus Notes agent, you'll be able to update a specific field in all selected Lotus Notes documents with new data.

Dim session As NotesSession
Dim ws As NotesUIWorkSpace
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim FieldName As String, NewValue 
As String, Message As String Dim item 
As NotesItem Dim YesNo As Variant Dim i As Integer

Sub Initialize
Dim session As New NotesSession
Set ws = New NotesUIWorkSpace
Set db = session.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set doc = dc.GetFirstDocument 
FieldName = Inputbox$("Enter Field Name.  
Enter this value very carefully.  
Spelling counts.","Enter Field")
If FieldName = "" Then Exit Sub 
NewValue = Inputbox$("Enter the new value.  
Enter 'Quit' to abort.","Enter Value")
If NewValue = "Quit" Then Exit Sub
Message = "Field Name: " & FieldName & Chr$(13) & _
"New Value: " & NewValue & Chr$(13) & _
"Records to be Updated: " & 
Cstr(dc.Count) & Chr$(13) & Chr$(13) &_
"Do you wish to continue?"
YesNo = Messagebox(Message,36,"Continue?")
If YesNo = 7 Then Exit Sub
For i = 1 To dc.Count
Set doc = dc.GetNthDocument(i)
Set item = doc.ReplaceItemValue(FieldName,NewValue)
Call doc.Save(True, True)
End Sub


This tip is overly complex. It ignores a simpler, method already available in the documentcollection class.

Call dc.StampAll(FieldName,NewValue)

—Gene K.


Don't forget that the NotesDocumentCollection.GetNthDocument gets extremely slow when the number of documents in the NotesDocumentCollection is large.
—Rhodri H.

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip library by member Mick Crowder. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

Dig Deeper on Lotus Notes Domino Agents

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.



  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...