Intelligent merging

S

Steve Wylie

A colleague of mine at work is doing a Word 2000 print
merge and really needs an "intelligent" merge that is
rather outside our scope of expertise for merging. I
was hoping that some kind soul on this newsgroup would be
able to help, or point us in the right direction.

She has an Excel spreadsheet with a thousand or so
records, each record is the banking details of an
employee.

Each record includes payroll reference, employee name,
bank branch name, bank sort code and employee's account
number.

The merge will produce bank details to go to various
banks. Typically each employee will have their bank
details, and some standard information that does not
change, on one sheet of paper, and this is sent off to
the bank. This is no problem.

However, lots of employees have the same bank sort code,
because they hold their account at the same branch as
certain other employees. If, for instance, 47 employees
have their account at the local Township Bank, the
Township Bank does not wish to receive 47 separate sheets
of paper with one employee's name on each. Therefore, we
need a way for the merge to tell when there is a section
of identical consecutive sort codes (the Excel sheet is
sorted by sort code), and where there is, to print these
all on one sheet of paper as a listing, and not to do one-
page-per-record as it would normally do.

I am aware that this sort of task has been explained in
help groups before, and indeed I have located a Microsoft
Knowledge Base article explaining something approaching
this (article number 105888), but there is a complication
and I cannot figure out how to work around it or even
whether it is possible in Word.

Here is the complication:

The way our company wants it, is that where there are 9
or less consecutive sort codes, these can be printed one
employee per page, like a normal merge. There is some
standard information on one page, and merged information
of the branch sort code, the bank's name and the branch's
name, then the employee details underneath.

However, where there are 10 or more employees, in
addition to the standard bank branch information and sort
code, etc, instead of the individual employee details
there will be a line at the bottom saying "see attached
sheet". The attached sheet then consist of the bank
details listed out for the 10+ employees concerned.

So for a single record you would have (in addition to a
lot of static details at the top):

Branch sort code: 12-34-56
Bank name: Township Bank
Branch name: Hamley Street branch

John Smith 12-34-56 555657565

But for 10 or more employee in a bunch who have the same
bank branch you would have:

Branch sort code: 12-34-56
Bank name: Township Bank
Branch name: Hamley Street branch

See list overleaf.

Then there would be a page break and you'd have:

John Smith 12-34-56 555657565
Jane Peterson 12-34-56 555870999
Michael Dee 12-34-56 555665432
Alex Michaels 12-34-56 555121345


I am hoping that the Word merge codes can provide a
solution. The merge has, as you can see, hard and fast
rules controlling which records are merged to which
format.

Could anyone who has experience of this kind
of "intelligent" merge point me in the right direction?
Or perhaps, dare I ask, with a full solution?

Thank you very much for reading this far!

Steve Wylie
 
P

Peter Jamieson

If you have an existing solution that nearly works using the { NEXTIF }
approach, consider using a DATABASE field to get the count of records with a
particular sort code. To do this you would typically need to
a. insert a DATABASE field. Use the Database toolbar, and create a filter
on the sort code column. Just pick any old sort code in the file and say you
want a sort code equal to that. You will probably need to use ODBC to
connect to the data in order to succeed in step (b), and that will probably
require you to use ODBC when you set up the data source as well.
b. modify the DATABASE field so it returns the count of records that
matches the "current" sort code, minus 10 (see below)
c. nest the DATABASE field inside an IF field to insert the additional text

See list overleaf<page break>

when the result of the DATABASE field is >= 0

So e.g. if the DATABASE field that Word generates is

{ DATABASE <connection info> \s "SELECT * FROM sheet1 WHERE
sortcode='303030'" \h }

modify it to

{ DATABASE <connection info> \s "SELECT count(*)-10 FROM sheet1 WHERE
sortcode='{ MERGEFIELD sortcode}'" }

(You may need to use

{ DATABASE <connection info> \s "SELECT count(*)-11 FROM sheet1 WHERE
sortcode='{ MERGEFIELD sortcode}'" }

)

Ensure you remove the \h - that means Word will treat the result as a piece
of text, not a table.

Then you'll need something like

{ IF { DATABASE field as above } >= 0 "See list overleaf<page break
character>" "" }

Precisely how you slot that into your existing merge document depends on
exactly which approach you have adopted, but you obviously only want the IF
field to be executed for the first record with a particular sort code.

All the {} need to be the field code braces you can insert with ctrl-F9.
 
S

Steve Wylie

Hi Peter

I'm afraid in order for your suggestion to work you are going to need to
take a step backwards and outline the mergecodes required in more detail.
Your explanation assumes a knowledge of the other merge fields that I don't
have.

Steve
 
P

Peter Jamieson

In that case, IMO the best thing to do is skim through the stuff on fields
in Word help, create a simple merge with a few fields in and use Alt-F9 to
see what you have inserted, then try inserting a database using Word's
database toolbar (enable with Tools|Customize), checking the "Insert as
Field" box in the last step in the dialog. Then if you're still stumped, let
us know what the first sticking point is. There's also stuff about merge at
http://www.mvps.org/word that you may find useful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top