Thanks for the quick reply. I'm just not sure when to use Format() in
my code. The structure of my merge function, all launched from a
command button on an Access form, is this:
1. Build recordset of values to be modified.
2. Build SQL "make table" query string using IF, SELECT, and IIF on
recordset fields. Calculations are in the SQL. Also include
unmodified fields from three tables.
3. Make new querydef using SQL string and execute, creating a temporary
table.
4. Open Word template with .OpenDataSource on temporary table.
5. Execute merge, save document, and close Word.
Would I have to add a step between 3 and 4 to Format() all numeric
fields to text? Or could the step 2 SQL "make table" statement force a
text format? Could CStr be used somewhere?
Thanks again.
I am not sure that using DDE would solve this particular problem because I'm
not convinced that it will retrieve the numbers as you see them in Access,
particularly since Word may well strip off leading and trailing zeros
whatever you do. However, you should be able to force a DDE connection in
OpenDataSource using e.g.
ActiveDocument.MailMerge.OpenDataSource _
Name:="<database name", _
Connection:="TABLE t1", _
SQLStatement:="SELECT * FROM [t1]", _
SubType:=wdMergeSubTypeWord2000
to connect to a table. Use Connection:="QUERY q1" to connect to a query
called q1. Remove the SubType parameter if you're using Word 2000.
This should avoid OLEDB/ODBC dialog boxes but you may still see
security-related questions.
> Would I have to add a step between 3 and 4 to Format() all numeric
> fields to text? Or could the step 2 SQL "make table" statement force a
> text format? Could CStr be used somewhere?
In your Maketable query you should be able to use format type functions as
well as IF, IIF etc. (I think!). You can certainly do it in an ordinary
SELECT query. However, again, I am not convinced that there is enough
information in your data to generate the correctly formatted numbers,
particular if there is a mix of numeric and non-numeric data in the column
in question. If you maintain an additional column that tells you how many
digits precision you are using in that column in each record, maybe it would
be easier. Also, when you use a MAKETABLE query, it is possible that Access
will generate a column with a numeric data type - I suepct you might have to
avoid that by creating your table with the column types you need and
inserting data into it as a separate step. (I don't know Access well enough
to tell you that stuff).
Peter Jamieson
> Thanks for the quick reply. I'm just not sure when to use Format() in
> my code. The structure of my merge function, all launched from a
[quoted text clipped - 26 lines]
>>
>> Doug Robbins - Word MVP
cjg.groups@gmail.com - 07 Jul 2006 04:01 GMT
Peter, at first glance, adding SubType to OpenDataSource may have
worked. It required no additional changes to my code or templates. I
will test further to ensure it merges all the different potential
precisions.
Doug, thanks for the Format() tip. I will keep that as a backup.
Your time was greatly appreciated, thank you.
> I am not sure that using DDE would solve this particular problem because I'm
> not convinced that it will retrieve the numbers as you see them in Access,
[quoted text clipped - 63 lines]
> >>
> >> Doug Robbins - Word MVP