Examples: BuildCollection method

This agent creates note collections based on form and view elements in the current database. The work occurs in a sub, which creates the note collection depending on the input parameters, builds the collection, then clears the collection.

Sub Initialize
  Dim s As New NotesSession
  Dim db As NotesDatabase
  Set db = s.CurrentDatabase
  Dim stream As NotesStream
  Set stream = s.CreateStream
  Dim nc As NotesNoteCollection
  Set nc = db.CreateNoteCollection(False)
  REM Export forms
  Call ExportFormView(True, False, s, db, stream, nc)
  REM Export views
  Call ExportFormView(False, True, s, db, stream, nc)
  REM Export forms and views
  Call ExportFormView(True, True, s, db, stream, nc)
  REM Test bad call
  Call ExportFormView(False, False, s, db, stream, nc)
End Sub

Sub ExportFormView(form As Boolean, view As Boolean, _
session As NotesSession, db As NotesDatabase, _
stream As NotesStream, nc As NotesNoteCollection)
  REM Check parameters and set up filename
  If form And view Then
    filename$ = "formview"
  Elseif form Then
    filename$ = "form"
  Elseif view Then
    filename$ = "view"
    Messagebox "Form and view both false",, "No action"
    Exit Sub
  End If
  REM Open dxl file as stream
  filename$ = "c:\dxl\" & filename$ & ".dxl"
  If Not stream.Open(filename$) Then
    Messagebox "Cannot open " & filename$,, "Error"
    Exit Sub
  End If
  Call stream.Truncate
  REM Create note collection
  Call nc.SelectAllNotes(False)
  If form Then
    nc.SelectForms = True
    nc.SelectSubforms = True
    nc.SelectSharedFields = True
  End If
  If view Then
    nc.SelectViews = True
    nc.SelectFolders = True
  End If
  Call nc.BuildCollection
  REM Export DXL
  Dim exporter As NotesDXLExporter
  Set exporter = session.CreateDXLExporter(nc, stream)
  Call exporter.Process
  REM Close stream and clear collection
  Call stream.Close
  Call nc.ClearCollection
End Sub