Is it possible to look at the SQL of an Access query without running it?

JeffreyWeir

Super Moderator
Staff member
Joined
Mar 22, 2011
Messages
357
Reaction score
0
Points
0
Location
New Zealand
I've started using Access, and finding it very poorly designed and badly documented.

My previous experience was on SQL Server, where you can of course view the SQL of a query and the query results at the same time. Not only does it look like you can't do this in access, but also whenever I switch between SQL view and Query view it retriggers the query. ARGGGGG!!!

In fact, I have several queries that I really really do not want to run, but really really want to view the SQL. But I can't work out how.

Can anyone enlighten me as to whether this is possible?

I'm on the verge of just ditching Access altogether in favour of SQL Server. Only thing holding me back is that Access is more widely available to my users.
 

JP2112

New member
Joined
Mar 21, 2011
Messages
8
Reaction score
0
Points
0
Location
NYC
Website
www.jpsoftwaretech.com
The specific instructions depend on your version of Access. In 2003, right click the query in the database window and choose "Design View". Then go to View > SQL view to see the SQL.
 

JeffreyWeir

Super Moderator
Staff member
Joined
Mar 22, 2011
Messages
357
Reaction score
0
Points
0
Location
New Zealand
Hi JP. Sorry, forgot to give the version. I'm using 2010 at home (where I am just now) and 2003 at work. In 2010 the database window has been replaced with the navigation pane, and the VIEW opiton is in the ribbon. While the View option has a dropdown from which you can select SQL view, you have to first run the query before this becomes selectable. If you haven't run the query, then the View option is grayed out.
You don't have access to the View option by right clicking.

I'll try your suggestion on 2003 in a couple of hours when I'm at work, but I swear that I had much the same problem there, in that yes you can view the SQL but not without running the query first, and if you want to then switch from the SQL view to look at the results for just a quick peek, the query automatically refreshes.
 

JP2112

New member
Joined
Mar 21, 2011
Messages
8
Reaction score
0
Points
0
Location
NYC
Website
www.jpsoftwaretech.com
I am able to do it without actually running the query. If you switch from SQL view to 'Datasheet' view (which is the result of the execution of the query) then yes you actually have to execute the query :)

You could also use VBA to view each query. See http://www.codeforexcelandoutlook.com/blog/2011/07/list-all-ms-access-queries-database/ for a way to view each query's SQL statement in the Immediate Window. That code may not work in Access 2010, however.

If Access 2010 forces you to run the query before you can view the SQL, that is terrible.
 

Ken Puls

Administrator
Staff member
Joined
Mar 13, 2011
Messages
2,521
Reaction score
6
Points
38
Location
Nanaimo, BC, Canada
Website
www.excelguru.ca
Excel Version(s)
Excel Office 365 Insider
Hi Jeffrey,

I can do it without executing the query in 2010:
  • Find the query in the navigation pane
  • Right click and choose Design View
  • On the Design Tab change it to SQL View
That doesn't execute the query as you never get to Datasheet view

Seems to me that someone might want to make an addin for Access that adds "SQL View" to that right click menu!
 
Top