PDA

View Full Version : Solved: Counting records in a mail merge from within the macro



peacenik
03-20-2007, 11:22 PM
I am doing a mail merge from a text file generated by another application to do Address labels. Because I do not know how many records my users are going to select for the Address labels, I have created a 40 page document for mail merge. Obviously, this does not please some of our users. What I would like to be able to do is to detect before printing how many records are present and expand the number of pages in the mail merge to suit the number of records. If I need to I can use a dialog box to ask the user how many, but I would prefer to be able to do this totally behind the scenes. I haven't been able to find any object property that tells me how many records there are. I am using Word 2000 :(

Any ideas? Thanks for reading.

TonyJollans
03-21-2007, 03:32 AM
To be blunt, you're not making any sense. When you set up a mail merge you create a model for a single merged record; the merge itself then creates one copy of it per record. You don't need to know, nor do anything to allow for, the number of records actually merged - except to make sure you have enough stationery for the physical print.

peacenik
03-21-2007, 03:43 AM
When you do address labels you need the next name and address to appear on the same page. Usually there are two or three columns of about 8 labels. word handles this with a command ({next record} or something like that). It will only print as many records as you have included instances of the address fields. I have replicated this hundreds of times to cater for my estimated maximum number of instances but I am getting feedback that this isn't good enough. I would like to set the template that I am using with just two pages and create addtional pages based on need. To do this I need to know how many records are in the current mail merge instance.

Sorry about the confusion. Hopefully, this makes things clearer.

TonyJollans
03-21-2007, 04:47 AM
When you create a label mail merge all you need to do is set up the first page of labels - using the <<Next Record>> field on all but the first label. There is no requirement to know in advance how many records you will have - the merge itself takes care of that.

If it helps, there are some fairly detailed steps shown on Graham Mayor's web page, here (http://www.gmayor.com/mail_merge_labels_with_word_xp.htm).

peacenik
03-28-2007, 05:23 PM
Too easy. Thanks for your help Tony.