Hi Fred.
Thanks for your reply. There are no stored Queries involved. I'm just
trying to generate some SQL that will be used elsewhere in my VBA code.
Here's how I envision it:
If the TextBox is blank, the user clicks a command button next to it. The
Query Design Grid opens, and is completely blank (like when creating a new
Query). The user selects Tables, Fields, etc. and closes the QDG. The
TextBox is then populated with the resulting SQL.
If the TextBox contains SQL, the user clicks the command button, and the QDG
is populated with the SQL from the TextBox. The user makes changes, exits
the QDG, and the TextBox is populated with the changed SQL.
Is it just not possible for VBA to interface with the Query Design Grid? I
forgot to mention previously that I'm using Access 2003 (if that matters).
If not, perhaps I can create a Temp Query , then use your code to open it
and populate it with SQL. I'd make changes, save it, and then output the SQL
to a TextBox. I'll give this a try, however, if there is any way to
interface directly with the QDG, I'd love to hear about it.
-Michael
fredg said:
Hello.
I would like to use VBA to show the Query Design Grid, then after using the
QDG to select Tables, Fields, Criteria, etc., exit the QDG and have the
resulting SQL placed in a TextBox.
Is this possible?
-Michael
You wish to show the actual SQL as text in the control?
I think you need to separate this into 2 steps, using 2 different
command buttons.
Button 1:
DoCmd.OpenQuery "QueryName", acViewDesign
This opens the query in design view. Make whatever changes or
additions you wish.
Manually close and save the query.
Button 2:
Code the click event of this button:
Dim qdf As DAO.QueryDef
Set qdf = CurrentDb.QueryDefs("QueryName")
Me![ControlName] = qdf.SQL
Set qdf = Nothing