Examples: Copying an item

  1. This example of a form button creates a document in the current database, creates a Subject item with the value "NEW SUBJECT," and copies the Categories and Body items to it from the current document.
    Sub Click(Source As Button)
      Dim session As New NotesSession
      Dim workspace As New NotesUIWorkspace
      Dim db As NotesDatabase
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument, doc2 As NotesDocument
      Dim item As NotesItem
      Set uidoc = workspace.CurrentDocument
      Set doc = uidoc.Document
      Set db = session.CurrentDatabase
      Set doc2 = New NotesDocument(db)
      doc2.Subject = "NEW SUBJECT"
      Set item = doc.GetFirstItem("Categories")
      Call item.CopyItemToDocument(doc2, "Categories")
      Set item = doc.GetFirstItem("Body")
      Call item.CopyItemToDocument(doc2, "Body")
      Call doc2.Save(True, False)
    End Sub
  2. This example of a form button creates a document in the current database and copies to it all items from the current document.
    Sub Click(Source As Button)
      Dim session As New NotesSession
      Dim workspace As New NotesUIWorkspace
      Dim db As NotesDatabase
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument, doc2 As NotesDocument
      Set uidoc = workspace.CurrentDocument
      Set doc = uidoc.Document
      Set db = session.CurrentDatabase
      Set doc2 = New NotesDocument(db)
      Call doc.CopyAllItems(doc2)
      Call doc2.Save(True, False)
    End Sub