Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / May 2007

Tip: Looking for answers? Try searching our database.

Conditional page eject in "Catalogue" mail merge

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lüko Willms - 15 May 2007 04:05 GMT
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.
Peter Jamieson - 15 May 2007 08:30 GMT
>   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

>   I have a mailmerge of type "catalogue" and want to insert a page
> eject when a certain field changes. How do I do that?
[quoted text clipped - 16 lines]
> Yours,
> L.W.
Lüko Willms - 15 May 2007 15:19 GMT
Am Tue, 15 May 2007 07:30:53 UTC,  schrieb "Peter Jamieson"
<pjj@KillmapSpjjnet.demon.co.uk>  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.
Peter Jamieson - 15 May 2007 16:16 GMT
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

> Am Tue, 15 May 2007 07:30:53 UTC,  schrieb "Peter Jamieson"
> <pjj@KillmapSpjjnet.demon.co.uk>  auf
[quoted text clipped - 24 lines]
> Cheers,
> L.W.
Lüko Willms - 15 May 2007 22:37 GMT
Am Tue, 15 May 2007 15:16:42 UTC,  schrieb "Peter Jamieson"
<pjj@KillmapSpjjnet.demon.co.uk>  auf
microsoft.public.word.mailmerge.fields :

> <<It works OK, but the "hard page break charakter" does
> break the field -- there may not be a paragraph or page break within a
[quoted text clipped - 3 lines]
> ...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.
Doug Robbins - Word MVP - 16 May 2007 04:34 GMT
Try Ctrl+Enter

Signature

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

> Am Tue, 15 May 2007 15:16:42 UTC,  schrieb "Peter Jamieson"
> <pjj@KillmapSpjjnet.demon.co.uk>  auf
[quoted text clipped - 17 lines]
> Yours,
> L.W.
Peter Jamieson - 16 May 2007 08:04 GMT
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

> Am Tue, 15 May 2007 15:16:42 UTC,  schrieb "Peter Jamieson"
> <pjj@KillmapSpjjnet.demon.co.uk>  auf
[quoted text clipped - 17 lines]
> Yours,
> L.W.
Lüko Willms - 16 May 2007 16:14 GMT
Am Wed, 16 May 2007 07:04:14 UTC,  schrieb "Peter Jamieson"
<pjj@KillmapSpjjnet.demon.co.uk>  auf
microsoft.public.word.mailmerge.fields :

> 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.
Doug Robbins - Word MVP - 16 May 2007 17:43 GMT
Sounds to me like it would be simpler to just run a macro over the document
produced be executing the merge.

Signature

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

> Am Wed, 16 May 2007 07:04:14 UTC,  schrieb "Peter Jamieson"
> <pjj@KillmapSpjjnet.demon.co.uk>  auf
[quoted text clipped - 17 lines]
> Yours,
> L.W.
Doug Robbins - Word MVP - 15 May 2007 10:16 GMT
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

Signature

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

>   I have a mailmerge of type "catalogue" and want to insert a page
> eject when a certain field changes. How do I do that?
[quoted text clipped - 16 lines]
> Yours,
> L.W.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.