#  Other Applications & Softwares  > Word Formatting & General >  >  Mail merge - Total number of records in source data

## hungt

What formula or code returns the total number of records in the source data? It's not about VBA (In VBA is ActiveDocument.MailMerge.DataSource.RecordCount)

I have eg.

{ SET a "{ IF { MERGESEQ } < TotalRecCount "on" "off" \* MERGEFORMAT }" }

What to give in place of TotalRecCount?

----------


## macropod

There is no field for that.

----------


## hungt

Thank you for your answer.

Can not get TotalRecCount in some other way?

----------


## macropod

VBA - but you already knew that. Another way would be to add a field to the data source and add a value to just the last record, which you could test with a field coded like:
{IF{MERGEFIELD Last}= "" "on" "off"}
where 'Last' is the field name. Perhaps you could explain what you're trying to achieve?

----------


## hungt

> Another way would be to add a field to the data source



I do not want to add a field.

I give the actual files - a real problem

*1. Excel file*

*shop* *name* *sale*
1	A	435
1	B	643
1	J	4352
2	P	235
2	M	235
9	S	35
9	K	1555

*2. Word file*

{ IF { MERGESEQ } = "1" "Starting text
Document 1" "" }{SET current { MERGEFIELD "shop" } }
{ IF previous <> current "{ IF { MERGESEQ } > "1" "Final text
Document 1" "" }
------- Page Break -------- <- CTRL + ENTER
Starting text
Document 1
{ MERGEFIELD "shop" }	{ MERGEFIELD "name" }	{ MERGEFIELD "sale" }" "{ MERGEFIELD "shop" }	{ MERGEFIELD "name" }	{ MERGEFIELD "sale" }" }{ SET previous { MERGEFIELD "shop" } }
---------

I get the result

*Page1*

Starting text
Document 1
1	A	435
1	B	643
1	J	4352
Final text
Document 1

*Page2*

Starting text
Document 1
2	P	235
2	M	235
Final text
Document 1

*Page3*

Starting text
Document 1
9	S	35
9	K	1555


As you can see on page 3 is not
Final text
Document 1

So after { SET previous { MERGEFIELD "shop" } } 

I want to add

{ IF { MERGEREC } < TotalRecCount "" "Final text
Document 1"

But I do not know what to put in place of TotalRecCount

----------


## macropod

It appears you're trying to group records via a Catalogue/Directory mailmerge. It would have been helpful had you said so at the outset.

You can indeed use Word's Catalogue/Directory Mailmerge facility for this (the terminology depends on the Word version). To see how to do so with any mailmerge data source supported by Word, check out my *Microsoft Word Catalogue/Directory Mailmerge Tutorial* at:
http://windowssecrets.com/forums/sho...merge-Tutorial
or:
http://www.gmayor.com/Zips/Catalogue%20Mailmerge.zip
The tutorial covers everything from list creation to the insertion & calculation of values in multi-record tables in letters. Do read the tutorial before trying to use the mailmerge document included with it.

The field coding for this is complex. However, since the tutorial document includes working field codes for all of its examples, most of the hard work has already been done for you - you should be able to do little more than copy/paste the relevant field codes into your own mailmerge main document, substitute/insert  your own field names and adjust the formatting to get the results you desire. For some worked examples, see the attachments to the posts at:
http://www.msofficeforums.com/mail-m...html#post23345
http://www.msofficeforums.com/mail-m...html#post30327
http://windowssecrets.com/forums/sho...l=1#post928391

Another option would be to use a DATABASE field in a normal ‘letter’ mailmerge main document and a macro to drive the process. An example of this approach can be found at: http://answers.microsoft.com/en-us/o...1-1996c14dca5d
The DATABASE field can even be used without recourse to a mailmerge. An example of such usage can be found at: http://www.msofficeforums.com/mail-m...html#post67097

Alternatively, you may want to try one of the Many-to-One Mail Merge add-ins, from:
Graham Mayor at http://www.gmayor.com/ManyToOne.htm; or
Doug Robbins at http://bit.ly/1hduSCB

In addition to a 'Many to One' merge, the latter handles:
• Merge with Charts
• Duplex Merge
• Merge with FormFields
• Merge with Attachments
• Merge to Individual Documents
• Merge, Print and Staple

----------


## hungt

Thank you for your answer.

I can do with an extra field. I asked because I thought I could code a field, formula or function. If it is not difficult. With an additional field I can manage.

I know VBA very well

----------


## macropod

My *Microsoft Word Catalogue/Directory Mailmerge Tutorial* shows how you can do it with a dummy last record instead of with an extra field. The DATABASE field approach requires neither.

----------


## hungt

> My *Microsoft Word Catalogue/Directory Mailmerge Tutorial* shows how you can do it with a dummy last record instead of with an extra field. The DATABASE field approach requires neither.



Thanks for the tutorial
I will read

----------

