+ Reply to Thread
Results 1 to 9 of 9

Mail merge - Total number of records in source data

  1. #1
    Registered User
    Join Date
    05-02-2013
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    24

    Mail merge - Total number of records in source data

    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?

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Mail merge - Total number of records in source data

    There is no field for that.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    05-02-2013
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Mail merge - Total number of records in source data

    Thank you for your answer.

    Can not get TotalRecCount in some other way?

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Mail merge - Total number of records in source data

    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?

  5. #5
    Registered User
    Join Date
    05-02-2013
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Mail merge - Total number of records in source data

    Quote Originally Posted by macropod View Post
    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
    Last edited by hungt; 04-25-2017 at 07:18 PM.

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Mail merge - Total number of records in source data

    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

  7. #7
    Registered User
    Join Date
    05-02-2013
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Mail merge - Total number of records in source data

    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
    Last edited by hungt; 04-25-2017 at 07:35 PM.

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Mail merge - Total number of records in source data

    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.

  9. #9
    Registered User
    Join Date
    05-02-2013
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Mail merge - Total number of records in source data

    Quote Originally Posted by macropod View Post
    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Mail merge - Number of records
    By c_robertson in forum Excel General
    Replies: 6
    Last Post: 02-03-2021, 01:03 PM
  2. Mail Merge with Excel data - multiple records per page
    By FieldHaven in forum Word Formatting & General
    Replies: 1
    Last Post: 02-04-2016, 06:46 PM
  3. Automatic mail merge with PDF template and excel data source
    By Manish_Gupta in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-12-2014, 01:13 AM
  4. [SOLVED] mail merge with Excel data source
    By tjb in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-18-2005, 10:35 PM
  5. [SOLVED] how do i get my mail merge to update the data source at each merge
    By Steel_Monkey in forum Excel General
    Replies: 0
    Last Post: 11-30-2005, 04:45 AM
  6. Excel data source for Word mail merge
    By Bernie Simmonds in forum Excel General
    Replies: 2
    Last Post: 06-16-2005, 04:05 PM
  7. [SOLVED] mail merge- & data source - only taking 1st name in the list
    By harriet in forum Excel General
    Replies: 6
    Last Post: 02-20-2005, 10:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1