MailMerge Mutliple Records Sometimes

G

Gilley

Hi,

I am attempting to mailmerge into a report with data
exported into a CSV (comma-delimted file). The issue I
have run across is the following.

On the report, I may or may not have multiple products
listed. The problem is that I add the mergefields «Next
Record»«ITEMNO» for the lines in the report where multiple
items may or may not need to be listed. Any merge field
after these lines doesn't display if there are more «Next
Record»«ITEMNO» than actual records in the CSV file.

For example:
«Next Record»«ITEMNO»
«Next Record»«ITEMNO»
«Next Record»«ITEMNO»
«Next Record»«ITEMNO»
«ORDERNO»

The CSV file in this example only contains one record so
the additional Next Records aren't needed. But the
OrderNo will not display.

The way I have worked around this before is to put all the
ITEMNO merge fields at the bottom of the page. This does
elimate the problem. I have tried using conditional merge
statements with if, skipif, etc. But just haven't had any
luck.

Any help would be greatly appreciated. I have about four
more reports to produce and this is an issue for each one.

Warmest regards,
Gilley
 
D

Doug Robbins

Use a catalog type merge with the formfields in the cells of a one row table
with the OrderNo mergefield in the first column and run the following macro
over the result

' 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


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
Hi,

I am attempting to mailmerge into a report with data
exported into a CSV (comma-delimted file). The issue I
have run across is the following.

On the report, I may or may not have multiple products
listed. The problem is that I add the mergefields «Next
Record»«ITEMNO» for the lines in the report where multiple
items may or may not need to be listed. Any merge field
after these lines doesn't display if there are more «Next
Record»«ITEMNO» than actual records in the CSV file.

For example:
«Next Record»«ITEMNO»
«Next Record»«ITEMNO»
«Next Record»«ITEMNO»
«Next Record»«ITEMNO»
«ORDERNO»

The CSV file in this example only contains one record so
the additional Next Records aren't needed. But the
OrderNo will not display.

The way I have worked around this before is to put all the
ITEMNO merge fields at the bottom of the page. This does
elimate the problem. I have tried using conditional merge
statements with if, skipif, etc. But just haven't had any
luck.

Any help would be greatly appreciated. I have about four
more reports to produce and this is an issue for each one.

Warmest regards,
Gilley
 

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