Including name of query in the results

S

scorpiorc

Is there a way to include the name of the query in the query's results? The
data returned from the query is being pasted into Excel by the user, and I'd
like to have a field which shows which query the results cames from.
 
R

Roger Carlson

Sure, if you hard-code it. Suppose the name of your query is "MyQuery".
You can add a column in the query builder that looks like this:

QueryName: "MyQuery"

This will create a column named QueryName which will have MyQuery as it's
value in each row.

If you want to do this dynamically, you'd have to modify the query's SQL
property in code, save it, then execute it.

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
R

Ron Hinds

Edit the SQL of the Query, and add to the SELECT list: 'QueryName' AS
QueryName

substituting the name of your query. For instance, say I had a Query named
qryCustomerOrders. Most of the data is coming from table tblCustomerOrders.
So my SQL would look like:

SELECT 'qryCustomerOrders' AS QueryName, tblCustomerOrders.* FROM
tblCustomerOrders;

This will add a column to the result set called QueryName and populate it
with qryCustomerOrders.
 
Top