Hi Bruce,
One way to do this is with a Union query based on your existing queries.
Assuming the queries are called qry1, qry2, qry3 and you want them in
that order, and the field you want is called F1, you'd basically have
something like this:
SELECT F1, 1 AS QOrder FROM qry1
UNION
SELECT F1, 2 AS QOrder FROM qry2
UNION
SELECT F1, 1 AS QOrder FROM qry3
ORDER BY QOrder;
One can often use a "fake" query to generate the header line, e.g.
something like this: it doesn't matter what table you use provided the
WHERE criterion makes the query return just one record.
SELECT "---- file #1 ----" AS F1, 0 AS QOrder
FROM SomeTable WHERE ID=1
Just include this in the Union query above. Then export the result to a
text file, using the Advanced... button in the text export wizard to set
up a specification that exports only the field F1, skipping QOrder.
Other ways of doing this sort of thing include;
- use the VBA file I/O commands to create a text file, and write the
header line. Then, for each query in turn, open a recordset and iterate
through the recordset writing the field to the text file.
- use the VBA file I/O commands to create a text file containing the
header line. Then use DoCmd.TransferText to export each query to a
separate file. Finally, use the Shell() function to execute a Windows
command to concatenate all the files in the desired order, e.g.
COPY Header.txt + Qry1.txt + Qry2.txt [+...] Finished.txt
I have several queries which I want to export to a single text
file in a particular order, plus output a special header line
such as "---- file #1 ----".
Also, each query generates 4 fields. I only want to export
one particular field (which is named the same in each query).
Thanks...