Examples: Collecting all documents and unprocessed documents

  1. This example collects all the documents in a database with the AllDocuments property of NotesDatabase, and traverses the collection by using the GetFirstDocument and GetNextDocument methods of NotesDocumentCollection.
    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)
        Messagebox doc.Subject(0)
        Set doc = dc.GetNextDocument(doc)
      Wend
    End Sub
  2. This example collects all the documents in a database with the AllDocuments property of NotesDatabase, and traverses the collection by using the GetFirstDocument and GetNextDocument methods of NotesDocumentCollection. Alternatively, you can use the GetLastDocument and GetPrevDocument methods to traverse the collection backwards.
    Sub Initialize
      Dim db As New NotesDatabase _
      ("", Inputbox("Name of database file?"))
      Dim dc As NotesDocumentCollection
      Dim doc As NotesDocument
      Set dc = db.AllDocuments
      Set doc = dc.GetFirstDocument()
      While Not(doc Is Nothing)
        Messagebox doc.Subject(0)
        Set doc = dc.GetNextDocument(doc)
      Wend
    End Sub
  3. This example collects all the documents in a database with the AllDocuments property of NotesDatabase, retrieves a document by using the GetDocument method of NotesDocumentCollection, and displays its note ID.
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim db2 As New NotesDatabase(local, "test2.nsf")
      Dim collection As NotesDocumentCollection
      Dim docA As NotesDocument
      Dim docB As NotesDocument
      Set db = session.CurrentDatabase
      Set collection = db.AllDocuments
      Set docA = collection.GetFirstDocument
      Set docB = collection.GetDocument(docA) 
      Messagebox "Note ID: " & docB.NoteID
    End Sub