Including name of query in the results

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
You can hard-code a column with the query name ...

Add a column like this
QueryName: "qryMyQuery"
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top