Examples: Removing an item

  1. This example uses the Remove method of the NotesItem class to remove all the ModifiedBy items in the database. To handle multiple items with the same name, the code removes items in a loop that tests HasItem.
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim dc As NotesDocumentCollection
      Dim doc As NotesDocument
      Dim item As NotesItem
      Set db = session.CurrentDatabase
      Set dc = db.AllDocuments
      Set doc = dc.GetFirstDocument()
      While Not(doc Is Nothing)
        If doc.HasItem("ModifiedBy") Then
          Set item = doc.GetFirstItem("ModifiedBy")
          Call item.Remove
          Call doc.Save(True, False)
          Set doc = dc.GetNextDocument(doc)
        End If
      Wend
    End Sub
  2. This example uses the RemoveItem method of the NotesDocument class to remove all the ModifiedBy items in the database.
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase  
      Dim dc As NotesDocumentCollection
      Dim doc As NotesDocument
      Set db = session.CurrentDatabase
      Set dc = db.AllDocuments
      Set doc = dc.GetFirstDocument()
      While Not(doc Is Nothing)
        If doc.HasItem("ModifiedBy") Then
          Call doc.RemoveItem("ModifiedBy")
          Call doc.Save(True, False)
        End If
        Set doc = dc.GetNextDocument(doc)
      Wend
    End Sub