Looking for a nice XML merge example.

  • Thread starter Albert D. Kallal
  • Start date
A

Albert D. Kallal

Does anyone have an example, or "link" to a xml merge example for word?

What I am looking for is the "classic" invoice, or "repeating" data type
merge.

That means you have some single fields like Address, Name, Company, and then
you have a set of repeating fields:


PackageName Qty Price
Apples 12 $5.00
Oranges 6 $4.00

Etc. etc.

It seems to me that since XML models the type of data very nicely..I am
wondering if word 2003 can use merge fields with this xml data..and you can
get this repeating data into a "table" (hopefully with a minimal amount of
fuss..and code). Can the new word handle this xml type data for merge
fields..and "repeat" data for one letter with one customer...but "many"
detail lines?
(or, do we still have to write code to do this?).

Any good examples of the above type problem...and a xml mail merge to word?
 
D

Doug Robbins

Hi Albert,

I think it's a case of new Word OLD mailmerge. I haven't done anything with
XML myself, but I do know that fellow MVP Bill Coan has done quite a bit
with it, so I suggest that you ping him on the subject as I don't think that
I have ever seen him in this Newsgroup.

Doing a search on Google for XML Mail Merge in the microsoft.public.*
newsgroups however does not turn up anything that would indicate that xml
can be used directly with mailmerge.

My standard response to anyone who has the data in Access and wants to do
this sort of thing (invoices) is to use Access.



--
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
 
A

Albert D. Kallal

My standard response to anyone who has the data in Access and wants to do
this sort of thing (invoices) is to use Access.

Thanks a bunch...

The above is quite close to my take on this also (and, if you keep the
ms-access report plain..it converts to word very nicely). So, using a report
in ms-access is really about the best way to go here..

The reason I asked is that I plain to "update" my Super Easy ms-access to
word merge..and I would love to include a "end user" ability to choose the
"many" side for a merge...
 
D

Doug Robbins

Hi Albert,

Here's a "potted" answer that I sometimes give to people wanting to do the
"one to many" thing. One day, I might get around to further developing the
macro method to combine the "many" bits produced with the "ones". Problem
is, there can be so many variations of what the "one" part should be.

Word does not really have the ability to perform a "multiple items per
condition (=key field)" mailmerge.

See the "Multiple items per condition" item under the "Special merges"
section of fellow MVP Cindy Meister's website at

http://homepage.swissonline.ch/cindymeister/MergFram.htm

Or, if you create a Catalog (on in Word XP and later, it's called Directory)
type mailmerge main document with the mergefields in the cells of a one row
table in the mailmerge main document with the keyfield in the first cell in
the row and then execute that merge to a new document and then run the
following macro, it will create separate tables with the records for each
key field in them. With a bit of further development, you may be able to
get it to do what you want.

' 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
 
C

Cindy M -WordMVP-

Hi Albert,
Does anyone have an example, or "link" to a xml merge example for word?

What I am looking for is the "classic" invoice, or "repeating" data type
merge.
Basically, Word still doesn't support either XML data sources, nor
one-to-many mail merges. Both topics are covered on my site (Doug pointed
you at the one-to-many).

Dev Ashish (another Access MVP) covered this topic fairly well a couple of
years ago, on his site. You may also want to review that, if you've never
seen it before. Personally, if I'm working from an Access POV, dynamically
providing a data source for a mail merge, my inclination would be to put
the "many" data into a comma-delimited string, in a single cell. The user
would then have to select the data and format the paragraphs with tab
stops...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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