Manage Learn to apply best practices and optimize your operations.

Mail Merge Using Notes Only With 2 Button Clicks

Mail Merge is usually a simple process, but when the data is in Notes then the
process requires a number of steps (export to 123 and then to Exel and the to a
WP) or a complex OLE design.

Here is a simple method to Mail Merge directly from within Notes either to a
form letter or to print Labels directly onto envelopes from Notes.

Assume you have a set of documents with customers Names and Addresses as part
of the documents.
You wish to send a letter to all customers in the State of "Heaven" (or

First I created an Action Button in the Customer View called "Mail Merge". This
pops up an InputBox and prompts the user to enter a search string. A Full Text
Search is then performed and the results are placed in a folder.
The user then changes to the folder and selects either an action button in the
Folder to print the Names and Addresses directly onto envelopes or to print a
standard letter to all the found customers.
The letter can either be created in Notes in a Rich Text Field or copy/pasted
from a WP app into the RT field and the merged names and addresses are at the
top of the form in a table.

A Form must be created for the Envelope (MailMergeEnvelope)or the Letter ( or
MailMergeLetter), using a simple table with field inheritance to pick up the
names and addresses from the original customer documents placed in the folder.
Of course when printing envelopes then the printer properties must be set to
pull envelopes from the desired tray.

Simple - but very effective and requires only two button clicks - one to search
and one to print.
CODE to do the FT Search :
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim workspace As New NotesUIWorkspace
Dim doc As NotesDocument
Dim custview As NotesView
Dim mailfolder As NotesView
Dim collection As NotesDocumentCollection
Set db = session.CurrentDatabase
Set custview = db.GetView("Customers")
Set mailfolder = db.GetView("MailMerger")

'remove any docs in the mailfolder first
Set collection = mailfolder.GetAllDocumentsByKey( "XXX", True )
Call collection.RemoveAllFromFolder( "MailMerger" )

'prompt user for search string
searchfor = Inputbox ( "Enter Text to Search for" , "Mail Merge Search")
Set collection = db.FTSearch( searchfor & " " & " & " & "FIELD Form
contains Customer",0, FT_DATE_ASC )
Msgbox "Documents Found = " & Str(collection.count) & Chr(10) & Chr(10) &
"Change to the MAIL MERGE VIEW to see the results"
If collection.count > 0 Then
Call collection.PutAllInFolder( "MailMerger" )
End If

End Sub

CODE in Action Button in Folder
@Command([Compose]; ""; "MailMergeEnvelope")
@Command([Compose]; ""; "MailMergeLetter")

CODE in Form Action Button to Print Envelopes or Letters once the form is
composed when the Action Button in the folder is clicked:
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim workspace As New NotesUIWorkspace
Dim view As NotesView
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim uidoc As NotesUIDocument
Set db = session.CurrentDatabase
Set view = db.GetView("Mailing View")
Set collection = db.UnprocessedDocuments
Set uidoc = workspace.CurrentDocument

Set doc = view.GetFirstDocument
While Not doc Is Nothing
Call uidoc.FieldSetText("Cust_Title" , doc.Cust_Title(0))
Call uidoc.FieldSetText("Cust_FName" , doc.Cust_FName(0))
Call uidoc.FieldSetText("Cust_LName" , doc.Cust_LName(0))
Call uidoc.FieldSetText("Cust_Address1" , doc.Cust_Address1(0))
Call uidoc.FieldSetText("Cust_Address2" , doc.Cust_Address2(0))
Call uidoc.FieldSetText("Cust_Address3" , doc.Cust_Address3(0))
Call uidoc.FieldSetText("Cust_State" , doc.Cust_State(0))
Call uidoc.FieldSetText("Cust_Zip" , doc.Cust_Zip(0))

Call uidoc.refresh
Call uidoc.Print(1)
Set doc = view.GetNextDocument(doc)

End Sub

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...