例: Locating documents within a view or folder

  1. 次の例では、[By Category] ビューのすべての文書に最初から最後への順番でアクセスします。最後から最初の順番ですべての文書にアクセスするには、GetLastDocument メソッドと GetPrevDocument メソッドを使用します。
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Set db = session.CurrentDatabase
      Set view = db.GetView("By Category")
      Messagebox "View name: " & view.Name
      Set doc = view.GetFirstDocument
      While Not(doc Is Nothing)
        Messagebox "Subject: " & doc.Subject(0)
        Set doc = view.GetNextDocument(doc)
      Wend
    End Sub
  2. 次の例では、ビューを全文検索条件「Search string alpha」に一致する文書だけに制限し、ビューを一覧表示します。
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Set db = session.CurrentDatabase
      Set view = db.GetView("By Category")
      Call db.UpdateFTIndex(True)
      numDocs = view.FTSearch("""Search string alpha""", 0)
      If numDocs <> 0 Then
        Set doc = view.GetFirstDocument
        While Not(doc Is Nothing)
          Messagebox "Subject: " & doc.Subject(0)
          Set doc = view.GetNextDocument(doc)
        Wend
      End If
    End Sub
  3. 次の例では GetAllDocumentsByKey を使用し、[By Subject] ビューにおいてソートされた最初の列の最初の文字列が、ユーザーが Inputbox に入力した文字列と一致するすべての文書にアクセスします。
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim dc As NotesDocumentCollection
      Dim keyString As String
      keyString = Inputbox("Subject starts with?")
      Set db = session.CurrentDatabase
      Set view = db.GetView("By Category")
      Set dc = view.GetAllDocumentsByKey(keyString, False)
      Set doc = dc.GetFirstDocument()
      If dc Is Nothing Then
         Messagebox keyString,, "Not found"
         Exit Sub
      End If
      While Not(doc Is Nothing)
         Messagebox doc.Subject(0)
         Set doc = dc.GetNextDocument(doc)
      Wend
    End Sub
  4. 次の例では GetDocumentByKey と GetNextDocument を使用し、[By Subject] ビューで、ソートされた最初の列の最初の文字列が、ユーザーが Inputbox に入力した文字列と一致するすべての文書にアクセスします。
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Dim keyArray(1 To 1) As String
      keyArray(1) = Inputbox("Subject starts with?")
      Set db = session.CurrentDatabase
      Set view = db.GetView("By Subject")
      Set doc = view.GetDocumentByKey(keyArray)
      If doc Is Nothing Then
        Messagebox keyArray(1) & " not found"
        Exit Sub
      End If
      subj = Left(doc.Subject(0), Len(keyArray(1)))
      While Not(doc Is Nothing) And subj = keyArray(1)
        Messagebox "Subject: " & doc.Subject(0)
        Set doc = view.GetNextDocument(doc)
        subj = Left(doc.Subject(0), Len(keyArray(1)))
      Wend
    End Sub
  5. 次の例では、すべての返答と返答文書への返答を前後に移動することにより、ビュー内のすべての文書にアクセスします。
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Dim Child As NotesDocument
      Dim grandChild As NotesDocument
      Set db = session.CurrentDatabase
      Set view = db.GetView("By Subject")
      Set doc = view.GetFirstDocument
      While Not(doc Is Nothing)
        Messagebox "Main document: " & doc.Subject(0)
        Set child = view.GetChild(doc)
        While Not(child Is Nothing)
          Messagebox "Response: " & child.Subject(0)
          Set grandChild = view.GetChild(child)
          While Not(grandChild Is Nothing)
            Messagebox "Response to response: " & _
            grandChild.Subject(0)
            Set grandchild = _
            view.GetNextSibling(grandChild)
          Wend
          Set child = view.GetNextSibling(child)
        Wend
        Set doc = view.GetNextSibling(doc)
      Wend
    End Sub
  6. 次の例では、[By Category] ビューの各文書について、その文書が返答文書かどうかを示し、さらに文書の第 1 レベルの返答文書数を示すメッセージを表示します。
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim dc As NotesDocumentCollection
      Dim doc As NotesDocument
      Set db = session.CurrentDatabase
      Set view = db.GetView("By Category")
      Set doc = view.GetFirstDocument
      While Not(doc Is Nothing)
        Set dc = doc.Responses
        If doc.IsResponse Then
          isResponse = _
          "This document is a response document."
        Else
          isResponse = _
          "This document is not a response document."
        End If
        Messagebox "Subject: " & doc.Subject(0) _
        & Chr(10) & isResponse & Chr(10) & _
        "This document has " & dc.Count _
        & " response documents."
        Set doc = view.GetNextDocument(doc)
      Wend
    End Sub
  7. 次の例はフォーム上のボタンで、現在の文書のコピーを「My Favorite Documents」という名前のフォルダに入れます。
    Sub Click(Source As Button)
      Dim workspace As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      Set uidoc = workspace.CurrentDocument
      Set doc = uidoc.Document
      Call doc.PutInFolder("My Favorite Documents")
    End Sub