Putting an end to the frustration of mail merge

This tip provides an answer for anyone who has ever struggled with a Lotus Notes to Microsoft Word mail merge.

This Content Component encountered an error

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

Dig deeper on LotusScript

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com'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 ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close