Examples: GetDocument method

This agent reports on documents in a database. The document collection dc2 contains all "Test" documents. The report is written to the screen.

Sub Initialize
  Dim session As New NotesSession
  Dim db As NotesDatabase
  Dim dbName As String
  dbName = "learning.nsf"
  
  Dim searchFor As String
  searchFor = "test"
  Dim dc1 As NotesDocumentCollection
  Dim doc1 As NotesDocument
  Dim dc2 As NotesDocumentCollection
  Dim doc2 As NotesDocument
  
  Dim message As String, verb As String  'report information
  
  Set db = session.GetDatabase( "courseServer", dbName)
  Set dc1 = db.AllDocuments
  Set dc2 = db.AllDocuments
  Set dc2 = db.FTSearch(searchFor, 0)
  If dc2.count = 0 Then 
    Messagebox "No " & searchFor & " documents found", , _
    Ucase(dbName)
    Exit Sub
  End If
  
  Set doc1 = dc1.getFirstDocument
  message = ""
  While Not doc1 Is Nothing
    Set doc2 = dc2.getdocument (doc1)
    If Not doc2 Is Nothing Then
      verb = " is a "
    Else
      verb = " is not a "
    End If
    Message = message&Chr(13)&Chr(10) & _
    doc1.GetItemValue( "Subject" )(0) & _
    verb & searchFor
    Set doc1 = dc1.getNextDocument(doc1)
  Wend
  Messagebox message, , "Documents in " & dbName
End Sub