Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the raw SQL from an access query to excel

Status
Not open for further replies.

UWTechie

Programmer
May 24, 2001
18
0
0
CA
When you link an access query to an excel sheet(i.e. using MS Query), is there some way to transport the actual sql over, and put it on another page? I know that I could just copy and paste, but I would like to know if there is some sort of automated way to get it sent over.

Also, once it is transferred, is there some way to run the actual query right from excel, thus eliminating the need to know where the original .mdb is (i.e. the thing still works if the .mdb is moved or renamed).

Thanx
 
Use the SQL property of the QueryDef Object

Dim DBS as database
Dim qdef as QueryDef
Dim strSQL
Set dbs = currentdb()
Set qdef = dbs.querydefs("YourQuery")
strSQL = qdef.SQL' You've got your SQL now in a variable
Set everything = nothing, etc etc



Tyrone Lumley
augerinn@gte.net
 
Where do I use this from? I am pretty new with Excel and I know very little (as in next to nothing) about VBA...
I was looking through the online help books, but there was nothing about this kind of stuff there...
Could you please be a bit more explicit in what I need to do?

Thank you very much

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top