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

read sql statement of a query using vba

P: 24
Hello,
I have created a query in Access and I want to be able to read the sql statement of the query using vba and then run it from excel vba.
That is instead of copying and pasting all the query sql statements i want to use code to read it directly from vba. Or alternatively run from excel the query on a recordset without the sql statement.

Thank in advance
Tsigos
Sep 21 '07 #1
Share this Question
Share on Google+
6 Replies


NeoPa
Expert Mod 15k+
P: 31,186
Each QueryDef (saved query) object in Access has a .SQL property with (strangely enough) the SQL string in it.
However, you're probably better off running the query remotely from Excel rather than trying to execute the same SQL. Syntax differs and so does the data sources that are available (and how they are referred to).
Sep 21 '07 #2

P: 24
I have tried copying the code from access to excel vba and it works fine. No need to convert any references or like *.to % or anything. Since it works any ideas on how to get this code from querydefs???

Thanks again!!
Sep 21 '07 #3

Denburt
Expert 100+
P: 1,356
Since you haven't posted any code I really don't understand the question. I would simply link to the query Via Excel then use something to refresh it or re query in Excel when needed.
Sep 21 '07 #4

NeoPa
Expert Mod 15k+
P: 31,186
I have tried copying the code from access to excel vba and it works fine. No need to convert any references or like *.to % or anything. Since it works any ideas on how to get this code from querydefs???

Thanks again!!
Please check out post #2 again. I answer that question as the first sentence (paragraph).
Sep 21 '07 #5

P: 24
thanks vey much for the prompt replys
you pointed me directly, i hadn't use .sql statement before but now i figured out how it works.
Excellent job u do.
Thank again
Sep 21 '07 #6

NeoPa
Expert Mod 15k+
P: 31,186
Thank you. You're welcome.
It's always nice to be appreciated.
Sep 21 '07 #7

Post your reply

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