I was thinking maybe if I used a database field to perform an sql query
on the existing connection, but I can't work out how to get the
database field to point to the existing connection. Is this possible?
You can't set up the database field so that it picks up the existing
connection (i.e. you can't specify a switch or something like "Current
Connection") - you have to specify the connection parameters in full. So if
the connection details need to change dynamically, you would need to use
code prior to the merge to get the correct connection details, build the
correct SQL, and insert or modify a suitable DATABASE field. You might find
that you have locking/concurrency problems with some data sources.
Alternatively I was thinking if I there was some kind of temporary
variable I could populate, that would display on the page, then I could
use a MailMergeBeforeRecordMerge event to retrieve the field value and
use mid$ to achieve the inner text and write it to the temporary
variable. Is this possible?
You can indeed use MailMergeBeforeRecordMerge to get the field value and use
mid$. all you then have to do is decide how to stuff the result into the
mail merge main document. Unfortunately you can't create a new data source
column dynamically so you can't use a MERGEFIELD field. If you use bookmarks
to specify where you need the text to go, you need to make sure that you
bookmark the text you insert so that you can delete it or overwrite it when
you process the /next/ record. In my view, if your text is simple (no weird
Unicode characters such as zero-width spacers and so on), and there is
always going to be some text to insert (even if it is only a single space),
then the simplest approach is to assign the text to a Word document
variable, use a { DOCVARIABLE } field where you want to insert it, and make
sure you update the field before the record is merged.
Peter Jamieson