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.
'Declarations: 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 'Initilaize: 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) Next 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.