modification to merge field before mail merge

  • Thread starter Pawel J. Glowacki
  • Start date
P

Pawel J. Glowacki

In mail merge I need to split one field form datasource into 3 parts (string
will be separated by - sign) and put in different places in document. I can't
modify datasource, so I need to do this in word, probably using macros?
 
P

Peter Jamieson

You have the following options:
a. use the MailMerge Events in the Word object model. That's the only
"official" way you can execute a macro during a merge. Since you can't
actually alter the content of the data that Word inserts with its MERGEFIELD
fields, you have to use another approach to get the data into the document.
You can either insert the data directly using VBA, if you know where it
needs to go, or insert the values into Document Properties and use {
DOCPROPERTY } fields to insert them (Merge should re-execute the fields as
each record is merged) or into Document Variables and use { DOCVARIABLE }
fields to insert them.
b.do the merge, perhaps inserting placeholders for where you want the data
to go, and postprocess the output
c. use OpenDataSource to specify SQL that gets you the data you really
need. This may be possible if
- Word accesses the data source using a suitable dialect of SQL such as
Jet SQL or Transact SQL. Notice that Word does, or can, access several types
of data source using Jet SQL, e.g. Access, Excel, and in some cases,
delimited text files. If it opens the data source using its own converters
you're out of luck as its internal SQL dialect is too simple and doesn't
have functions such as left, mid etc.
- the SQL query string length can be limited to less than around 255 or
512 characters (depends on the data source and connection type)
- you have control over the merge - if you need to allow users to select
the data source, apply sorts//filters and selections, it's probably not
worth attempting.
d. use a DATABASE field to issue some Jet (or other type of) SQL to extract
bits of the string. You need a suitable dummy .mdb to do this easily, and
you must be confident that the string you want to split does not contain "
and/or ' characters. Unfortunately, MS appears to have done something that
screws up this approach in recent versions of Word 2003 and possibly 2002.
if you search the MailMerge group in Google using "Peter Jamieson DATABASE
field" you should find more info on this one.

Peter Jamieson
 

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