Can you return the query used by a recordsource?
Like Set rs= Currentdb.OpenRecordsource ("Select * from Table1;")
Then later, the equivalent of
Debug,print rs.sql (which doesn't exist)
and get Select * from Table1
Can you return the query used by a recordsource?
Like Set rs= Currentdb.OpenRecordsource ("Select * from Table1;")
Then later, the equivalent of
Debug,print rs.sql (which doesn't exist)
and get Select * from Table1
Put the sql string into a variable and refer to that in both instances?
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
Your title suggests you know the answer already
strSql = CurrentDb.QueryDefs("myQuery").sql
so
Set rs = currentdb.openrecordset(strSql)
Why would you want that when you have the stored query?
EDIT - or are you saying you want to know what stored query has that sql? I say no, not really. Any number of queries could contain that exact sql.
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.
Hmm okay.. well in my (often) convoluted way I was raising an error - and the error handler needed something to resume to.
The current recordsets sql seems as good as any.... but I couldn't get it to try...
I used something else in the end, but thanks for the solution as it's worth remembering.