Examples: Merge method (NotesDocumentCollection - LotusScript®)

This example searches a customer support database for all customers that have either bought a product or called for support within the past month, then prints their name to the screen.

Sub Click(Source As Button)
  Dim session As New NotesSession
  Dim db As NotesDatabase
  Set db = session.CurrentDatabase
  Dim dc1 As NotesDocumentCollection
  Dim dc2 As NotesDocumentCollection
  Dim doc1 As NotesDocument
  Dim monthago As New NotesDateTime("")
  monthago.SetNow
  Call monthago.AdjustMonth(-1)
  
  ' Not the most efficient way to find all customers where LastSale
  ' or LastCall was < one month ago, but it's just an example.
  Dim searchFormula As String
  searchFormula = {Form = "Customer" & LastSale > [} & monthago.DateOnly & {]}
  Set dc1 = db.Search(searchFormula,Nothing, 0)
  searchFormula = {Form = "Customer" & LastCall > [} & monthago.DateOnly & {]}
  Set dc2 = db.Search(searchFormula,Nothing, 0)
  Call dc1.Merge(dc2)
  
  Set doc1 = dc1.getFirstDocument
  Dim message As String
  While Not doc1 Is Nothing
    message = message & {
} & doc1.GetItemValue( "CustName" )(0)
    Set doc1 = dc1.getNextDocument(doc1)
  Wend
  Messagebox Mid$(message, 2), MB_OK, "Customers active in the last month"
End Sub