SQL

SQL

am 01.04.2008 11:37:28 von paulmitchell507

Is it possible to open an existing access query, modify the criteria
before save and closing using SQL?

I know that I could use SQL to code the query, but I want to make the
changes using SQL and then run a seperate query that is based on the
results of the amended query.

Re: SQL

am 01.04.2008 14:05:27 von Allen Browne

You can programmatically assign the SQL property of a QueryDef.

Given that the stub of the SQL statement (before the WHERE clause) and the
tail (after the WHERE clause) don't change, you would code it like this:

Dim strWhere As String
Const stcStub = "SELECT * FROM Table1 WHERE "
Const strcTail = " ORDER BY SomeField;"
strWhere = "SomeField = ...
CurrentDb.QueryDefs("Query1").SQL = strcStub & strWhere & strcTail

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"paulmitchell507" wrote in message
news:47ec6391-2ee2-4c8d-a85b-6d66e6ae4141@p25g2000hsf.google groups.com...
> Is it possible to open an existing access query, modify the criteria
> before save and closing using SQL?
>
> I know that I could use SQL to code the query, but I want to make the
> changes using SQL and then run a seperate query that is based on the
> results of the amended query.