Conditional page eject in "Catalogue" mail merge

L

Lüko Willms

I have a mailmerge of type "catalogue" and want to insert a page
eject when a certain field changes. How do I do that?

Let's say, this controlling field is called "Zimmer_Nr", as German
for Room_No.

I haven't done Winword programming for at least half a year and
can't remember how to do it, but I would need it for tomorrow...

MS-Office 2000, data source is an Excel sheet.

I was thinking to insert a mailmerge IF ... ELSE before the first
item in the data row, comparing the actual value of the mailmerge
field "Zimmer_Nr" to a DOCVARIABLE, and assign the current value of
the "Zimmer_Nr" to a DOCVARIABLE at the end of the data row.

Or can I access the field value indexed by the MERGESEQ value?

Yours,
L.W.
 
P

Peter Jamieson

I was thinking to insert a mailmerge IF ... ELSE before the first
item in the data row, comparing the actual value of the mailmerge
field "Zimmer_Nr" to a DOCVARIABLE, and assign the current value of
the "Zimmer_Nr" to a DOCVARIABLE at the end of the data row.

That is what you have to do but you can't set a DOCVARIABLE from a field so
you have to use SET and REF fields

e.g. put the following at the beginning of your document

{ IF { MERGESEQ } = 1 "{ SET previousZimmer_Nr "{ MERGEFIELD
"Zimmer_Nr" }" }" "" }

Then at the point where you want the page break

{ IF "{ MERGEFIELD "Zimmer_Nr" }" = "{ REF previousZimmer_Nr }" "" "<put a
hard page break character here>" }{ SET previousZimmer_Nr "{ MERGEFIELD
"Zimmer_Nr" }" }

All the {} need to be the special field braces you can insert using ctrl-F9.
You can probably get rid of a few of the double-quotes, especially if
Zimmer_Nr is always numeric.

A minor problem when using { MERGESEQ } is that it's not set to the current
record number when you preview, only when you actually merge, so the preview
does not necessarily work how you might expect.

Alternatively, if you are executing the merge from VBA, you can consider
using MailMerge events and directly altering the Mail Merge Main Document
when you detect a change in Zimmer_Nr

Peter Jamieson
 
D

Doug Robbins - Word MVP

The following macro will separate a catalog type mailmerge into separate
tables when the data in the first field changes.

' Macro to create multiple items per condition in separate tables from a
directory type mailmerge

Dim source As Document, target As Document, scat As Range, tcat As Range
Dim data As Range, stab As Table, ttab As Table
Dim i As Long, j As Long, k As Long, n As Long
Set source = ActiveDocument
Set target = Documents.Add
Set stab = source.Tables(1)
k = stab.Columns.Count
Set ttab = target.Tables.Add(Range:=Selection.Range, numrows:=1,
numcolumns:=k - 1)
Set scat = stab.Cell(1, 1).Range
scat.End = scat.End - 1
ttab.Cell(1, 1).Range = scat
j = ttab.Rows.Count
For i = 1 To stab.Rows.Count
Set tcat = ttab.Cell(j, 1).Range
tcat.End = tcat.End - 1
Set scat = stab.Cell(i, 1).Range
scat.End = scat.End - 1
If scat <> tcat Then
ttab.Rows.Add
j = ttab.Rows.Count
ttab.Cell(j, 1).Range = scat
ttab.Cell(j, 1).Range.Paragraphs(1).PageBreakBefore = True
ttab.Rows.Add
ttab.Cell(j + 1, 1).Range.Paragraphs(1).PageBreakBefore = False
For n = 2 To k
Set data = stab.Cell(i, n).Range
data.End = data.End - 1
ttab.Cell(ttab.Rows.Count, n - 1).Range = data
Next n
Else
ttab.Rows.Add
For n = 2 To k
Set data = stab.Cell(i, n).Range
data.End = data.End - 1
ttab.Cell(ttab.Rows.Count, n - 1).Range = data
Next n
End If
Next i


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

Lüko Willms

Am Tue, 15 May 2007 07:30:53 UTC, schrieb "Peter Jamieson"
<[email protected]> auf
microsoft.public.word.mailmerge.fields :

Thanks a lot for your help, and thanks too to Doug Robbins.
Then at the point where you want the page break

{ IF "{ MERGEFIELD "Zimmer_Nr" }" = "{ REF previousZimmer_Nr }" "" "<put a
hard page break character here>" }{ SET previousZimmer_Nr "{ MERGEFIELD
"Zimmer_Nr" }" }

I have chosen your approach because it seemed to be easier than
writing a whole VBA program, and because it was more like what I was
looking for. It works OK, but the "hard page break charakter" does
break the field -- there may not be a paragraph or page break within a
mail merge field. I had a similar problem already last year with
another project then.

I tried to insert an {AUTOTEXT NewPage} with NewPage being a blank,
but with a paragraph formatting forcing a page break before the
paragraph. That did not work either. I have now inserted "###" as a
special sequence of characters which I then change later to something
else with the paragraph formatting as mentioned above. That did work.


Cheers,
L.W.
 
P

Peter Jamieson

Well, it sounds as if you have what you need anyway, but...

<<It works OK, but the "hard page break charakter" does
break the field -- there may not be a paragraph or page break within a
mail merge field.
....I'm not sure what you mean here, because you can certainly insert a page
break and the field works as expected. Of course the second part of the
field code disappears onto the next page, but that's about it. What does not
work (or do you mean that for other reasons you do not want a page break
inside a field) ?

Peter Jamieson
 
L

Lüko Willms

<<It works OK, but the "hard page break charakter" does
break the field -- there may not be a paragraph or page break within a
mail merge field.

...I'm not sure what you mean here, because you can certainly insert a page
break and the field works as expected.

It didn't work for me. I used the "Insert" menu, item "Manual break"
(my retranslation from German), chosing "page break". That didn't
work. I had a similar problem last year with a paragraph mark in a
mailmerge field. The processing of the field would end at those hard
marks, either paragraph or page. When I replaced the paragraph mark
with the line brea (SHIFT-ENTER), then it worked.


Yours,
L.W.
 
D

Doug Robbins - Word MVP

Try Ctrl+Enter

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

Peter Jamieson

That's strange. I vaguely remember your query last year too.

If you want, despam my e-mail and send me a document where the problem shows
up, and I'll have a look. (remove "KillmapS"

Peter Jamieson
 
L

Lüko Willms

If you want, despam my e-mail and send me a document where the problem shows
up, and I'll have a look. (remove "KillmapS"

I can't send the mailmerge document I was working on ... but I could
try to produce one which shows the problem.

Anyway, I tried again Doug Robbin's suggestion to user the
CTRL-ENTER key combination, but that is only a shortcut to the same
form feed command.

Word simply stops processing the field when it encounters a New Page
or New Paragraph command. I had a new page for every record from the
data source.


Yours,
L.W.
 
D

Doug Robbins - Word MVP

Sounds to me like it would be simpler to just run a macro over the document
produced be executing the merge.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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