running self defined function in mailmergefield

A

ASB

hi,

I'm using automated mailmerge from access to word. there are som
datefields i want to convert to another date - not another format -,an
since it's the same function here, and instead of having to add mor
mergefields - and I allready have to much, using a Word doc as m
mergesource, with max 64 fields -. I thought of writing a simpl
function in VBA behind Word , attached to normal.dot, and then, just a
you have internal Word functions you can use in mergefields, call tha
function.
Like {MyFunction {Mergefield MyMergefield}}
Nobody seems to know, though, if this is possible, and if it is, ho
to do it.


Someone?

Thanx
 
P

Peter Jamieson

Nobody seems to know, though, if this is possible, and if it is, how
to do it.

1. It isn't possible - there is no facility to do what you are suggesting in
Word.

2. There are three main ways you can consider working around this problem.
a. preprocess your data into another format that gives you the fields you
really need
b. if you are using Word 2002 or 2003, use the Mailmerge object's Events in
VBA to process your source data and stuff the values you want into the
mailmerge main document as you process each record
c. merge to an output document, making sure that all the data you want to
alter is marked in some way so you can locate it later, then postprocess the
output using VBA.


If you have Access, using (a) to convert to an Access table and using an
Access query to provide the fields you really want is probably as good an
approach as any. In fact, you should be able to create a suitable .mdb file
on-the-fly using ADOX and ADO, as long as you can use them to create the
query. However, even if you convert to text format, if you use ODBC to
access your data you can specify an SQL query in the VBA OpenDataSource
method that connects to the data source. The SQL dialect in that case is Jet
SQL, so many of the common VBA functions are available. The problem with the
latter approach is that the SQL is limited to 255 or 511 characters. The
reason you cannot do this (unfortunately) when the data source is a Word
document is that Word does not use Jet SQL when it gets data via its
internal and external text converters - it uses a very simple SQL dialect
with no functions at all.

(Just returning to (1), a few years ago I had a long look around for some
way to do the sort of thing you suggest. Although there are some field types
that invoke VBA in some circumstances (e.g. MACROBUTTON fields and form
fields), the only field that could really be persuaded to execute some code
and replace the field with the result of that code, and do it when you
expected during a merge, was the INCLUDETEXT field. In order to persuade it
to do that, you have to write a Word text import converter that regards the
"subset" (often thought of as "range" or "bookmark") parameter of the field
as a piece of code to be executed, and passes it to a suitable interpreter,
which can in fact be some VBA functions that interpret the code. In other
words, it doesn't actually convert any text at all. I did write a converter
to do this, and it does work, but there are so many problems associated with
using it that it's probably not a good idea to try. e.g. everyone who uses
it has to have a copy, unfortunately the INCLUDETEXT field doesn't work
quite the way it needs to, and so on.).
 
Top