By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,968 Members | 1,180 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,968 IT Pros & Developers. It's quick & easy.

Getting sql string from a query

P: 23
Is it possible to programmatically get the sql string of a query object?
Jul 13 '09 #1
Share this Question
Share on Google+
3 Replies


jimleon
P: 74
If you go into the desing view of the query, right click on it and select 'sql view' you will see the query in text format.
Jul 13 '09 #2

P: 69
charli:

Try the following code to obtain the SQL for a query object in the current database:

Expand|Select|Wrap|Line Numbers
  1. Private Function GetQuerySQL(MyQueryName as String) as String
  2. Dim QD As DAO.QueryDef
  3.  
  4. Set QD = CurrentDb.QueryDefs(MyQueryName)
  5. GetQuerySQL=QD.SQL
  6.  
  7. End Function
FYI, the SQL property of a DAO.QueryDef object is read/write.

Regards,
sphinney

@charli
Jul 13 '09 #3

P: 23
Fantastic, thank you sphinney!
Jul 14 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.