Tip

Putting an end to the frustration of mail merge

During the 15 years I've been involved with Lotus Notes, many people have asked me about mail merge from Notes to Microsoft Word. I usually give them a vague answer along the lines of, "Yeah, you can do it. I wrote some code a while ago that worked. But I can't find it now."

Now consider that one of the most common questions for the Microsoft support department is how to do mail merge, and it becomes clear that mail merge is a source of endless frustration for users. I hope that this article will solve the problem, once and for all, at least when passing data from Notes to Word. In this article, I'll first explain how to use the sample mail-merge application that I wrote, then describe the LotusScript code that does the work.

Notes output to Word is driven by a setup parameter that specifies the contents of the exported data. Within the Notes database, find the view named Settings, then open the parameter named Export - Mail Merge. The first line of the setup specifies the default name of the export file from Notes. The second line controls whether a header line is included in the export. (It usually is.) The remaining lines specify the names of the Notes fields that are included in the export.

To perform a data export, the Notes user selects any set of documents, pulls down the Action menu, and executes Mail Merge. You can try this yourself with the sample. First, create a directory named c:\mail-merge\ and use the view All Form1 to select some documents. When testing the export, you should use the default name for the export file, because the sample Word file is expecting that. After doing the export, examine the output file to verify that the selected data is present. Because there is a TAB character between each data field, the columns may not line up neatly when you look at the file on the screen, but the file is okay

The sample Word document named Customer Letter uses the Notes export file. The details of how mail merge works within Word vary, depending on the version of Word you have. A simple test is to use the next/last record buttons on the Word mail-merge toolbar. (The mail-merge toolbar should appear when you open the sample Word document. The next/last record buttons are left and right arrows.) You should see each "merged" letter in turn, one for each record exported from Notes.

The coding behind this sample uses two constructs: a simple agent, and the body of the code within a script library routine. The agent, named Mail Merge, contains only one line, which is a call to the script routine named ExportData within the library named MiscLib. The single parameter for the script call is the name of the user-definable setup parameter (Export - Mail Merge). The reason for this arrangement is so that you can easily create other instances of mail merge. You might want to export a different set of fields for certain Word documents, or to export a different set of Notes documents that contain different field names. You can do either without any new programming. Just create another setup parameter, say Export - Mail Merge 2, and another agent, say Mail Merge 2. The new agent is just like the current one, except that it includes the name of the new setup parameter in its call to the script routine.

The LotusScript routine (ExportData) includes generous comments and should be readable to those who want to see how it works. One way to possibly improve the code would be to include the field separation character (currently TAB) as one of the lines in the user-definable setup. I did not do so because TAB is so commonly used as a field separator that it seemed safe to leave that definition within the code. But if any reader wants to make this change, or finds a bug in the code, please let me know!

Chuck Connell is president of .CHC-3 Consulting, which helps organizations with all aspects of Domino and Notes. He can be reached at Connell@chc-3.com.
 

This was first published in June 2005

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.