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 / August 2004

Tip: Looking for answers? Try searching our database.

MailMerge Mutliple Records Sometimes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gilley - 11 Aug 2004 19:54 GMT
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
Doug Robbins - 12 Aug 2004 00:35 GMT
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

Signature

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

Rate this thread:






 
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.