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

This was first published in November 2000

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.