This is how I solved most of the reporting in my notes applications.
The output of this routine is a document ready for printing, which is by itself
a collection of documents.
This is the internal working of the process...
you will need 2 forms for this routine to work
1. A page layout (Title/ Subtitle/ Date/ Header/ Footer/ Body[rtfield])
2. A document Template (e.g. status/ assigned to etc...)
The idea is the following many 'document templates' will be rendered on the
print layout, which eventually will be printed.
The specific code presented here, builds the collection as well based on some
user selections (the click is triggered from a dialog box).
The original form is called 'Main', the page layout is called 'PrintPreview',
the form for rendering each document for printing is called 'PrintItem'. The
real code discussed here is toward the end (last 15 lines or so).
Sub Click(Source As Button)
'Written by Riccardo Coen
'distributable freely, just keep these lines comments in.
Dim previewUidoc As notesuidocument
Dim uidoc As notesuidocument
Dim ws As New notesuiworkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim docSource As NotesDocument
Dim docPrintPreview As NotesDocument
Dim rtitem As NotesRichTextItem
Dim lookupView As notesview
Dim lookupCollection As notesdocumentcollection
Dim subject As String
Dim success As Variant
Dim coll As notesdocumentcollection
Dim i As Double
Dim formula As String
Dim parties As String
Dim status As String
Dim subtitle As String
Dim item As NotesItem
Dim cutOffDate As NotesDateTime
Dim authorsItem As notesitem
'...set value of doc...
Set uidoc = ws.currentdocument
Set db = session.CurrentDatabase
' STEP ONE
'build the list of document that we will need to print
formula = "Form = 'Main' "
parties = uidoc.fieldgettext("Parties")
status = uidoc.fieldgettext("Status")
tmp = ""
If parties <> "Any" Then
formula = formula & " & (! (@isnotmember( @explode('" & parties &
"'); Leader:Follower ))) "
If status <> "All" Then
If status = "Outstanding" Or status = "Assigned" Then
tmp = "Outstanding; Assigned"
formula = formula & " & (! (@isnotmember( @explode('" & tmp &
"'); Status )))"
Elseif status = "Overdue" Then
formula = formula & "& duedays < 0 "
formula = formula & "& Status = '"& status &"'"
Set cutOffDate = New NotesDateTime( uidoc.fieldgettext("Created") )
Set coll = db.search(formula, cutOffDate, 0)
' STEP 2
If coll.count>0 Then
'Create the document on which we will be adding output "the print preview"
Set docPrintPreview = New NotesDocument( db )
Set rtitem = New NotesRichTextItem( docPrintPreview, "Body" )
docPrintPreview.Form = "PrintPreview"
'lookup subject either on the view or... through a search
docPrintPreview.subject = APPLONGNAME '-> defined in script library
'and set the subtitle if required
subTitle = Status + " Action Points" + Chr$(10)
tmp = ""
If Parties <> "Any" Then
'get rid of the ; in the leaders list
tmp = Evaluate( "@replacesubstring('"+ Parties +"'; ';' ;
subtitle = subTitle + "Assigned to: "+ tmp(0) + "."
docPrintPreview.subTitle = subtitle
'the next step is needed since the user will need to delete this document once
he's printed it.
Set authorsItem = docPrintPreview.ReplaceItemValue(
"PrintPreview_Authors", session.UserName )
authorsItem.IsAuthors = True
'======The following variables are using for sorting purposes (THIS
USES EXTERNAL ROUTINES)
Redim sortKey(coll.count) As Variant
Redim docIds(coll.count) As String
For i=1To coll.count
Set docSource = coll.getnthdocument(i)
sortKey(i) = docSource.agendaitem(0)
Call qsortdocs(sortKey, docIds, 0, coll.count)
'======Up to here
'Now populate the body of the print preview
For i = 1 To coll.c
This was first published in November 2000