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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract SQL Code from a broken query 1

Status
Not open for further replies.

twifosp

Programmer
Jul 25, 2003
186
US
I have a query that uses a sub query in the select statement. Example:
Code:
Select * from 
(select * from tablea union select * from tableb)

I know that access will randomly remove your parenthesis in these examples and turn them into brackets. This has apparently happened to me and now I can't open the query in design view to fix it. The query errors out with an invalid bracketing error message and I can not edit the SQL.

Anyone know how to extract the code of the query, without using design view, so I can fix this and create a new query?
 
Press Ctrl+G to open the debug window. Then enter something in the debug window like the following and press enter:
Code:
? CurrentDb.QueryDefs("YourQueryName").SQL

Duane
Hook'D on Access
MS Access MVP
 
I tried this:
Code:
Sub test()
Print CurrentDb.QueryDefs("totals").SQL
End Sub
And the error message I get is: method not valid without suitable object.
 
I took the time to reply with a solution that has worked for me many times. You came back with some other code and ask why it doesn't work :-(

Why didn't you try what I suggested?

Duane
Hook'D on Access
MS Access MVP
 
Oh I see. When I press control G it opens up the visual basic editor. I assumed that's where your code went. I didn't notice that it has an IMMEDIATE box in the bottom where I am supposed to put your code.

It works, thank you sir!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top