> I dont want to use the mailmerge abilities for various reasons.
> So I created a recordset using the following commands:
[quoted text clipped - 28 lines]
>
> Thanks
Hi Peter,
This is not exactly what I would like. I would like to go to the
document, and add "fields" without having to change my VBA code.
Then, my VBA code would go through all the "fields" on the document,
and populate them from my recordset based on their name. In
otherwords my VBA code would discover which fields or on the document
and use their names to populate them with data from the recordset.
This way if a user decides they want one more "field" they just have
to use the Insert/Field to add one on their template.
Also anytime the document is opened it should reflect the current
values of the record.
Thanks
> There are various ways you could do this, but the easiest way is probably to
> use DOCVARIABLE fields because you do not then need to locate specific
[quoted text clipped - 30 lines]
> types you are using and to use format switches in your DOCVARIABLE fields to
> get what you need.
Peter Jamieson - 18 Aug 2004 20:47 GMT
If you want to do that, in essence you have to develop a set of features
rather similar to Mailmerge's - i.e. the user needs to be able to pick from
a list of possible column names in your data source (unless you just want to
let them enter any old name), you need to decide how to represent those
"placeholders" (cf. MERGEFIELD fields), how the user switches from
"placeholder" view to "results" view and back, how to populate your document
on open and preserve various pieces of information such as "current record",
and how exactly to do that in code.
That's a substantial amount of thought, design and coding. You may well find
packages that can already do it (it's clear from some posts in this
newsgroup that some people are using that kind of package as an alternative
to the built-in merge facilities), and you may well be able to find code
that does it, but I certainly don't have a suite of such code on tap,
although I occasionally think of developing something like that.
So all I could really do was point at a way (and I think it's a fairly
simple way) to inject ADO data into a Word document. It's really up to you
to decide whether or not to build on that. For example, if you get users to
put DOCVARIABLE fields in your document, you can fairly easily iterate
through the collection of fields looking for DOCVARIABLE fields, extract the
column name from each such field, see if there is an equivalent column name
in your ADO data source, and if so, create an appropriately named
Document.Variable and assign a value to it. If there isn't an equivalent
value you could create the Variable and assign some sort of error message to
it, or pop up a message box. There are other ways you could achieve the same
objective.
I've assumed you are connecting via ADO for a reason, but maybe all you need
to do is connect via OpenDatSource instead. And if you want to be able to
deal with various types of ADO source that you can't access via
OpenDataSource (because it has various failings) then another possible
approach might be to use ADO to create and populate a source (perhaps a .mdb
file) that can easily be accessed via OpenDataSource.
Just food for thought - sorry, I can't really do more than that.

Signature
Peter Jamieson
> Hi Peter,
>
[quoted text clipped - 47 lines]
> > types you are using and to use format switches in your DOCVARIABLE fields to
> > get what you need.