tags:

views:

139

answers:

1

I have done

Dim qd as querydef
set qd = Querydefs("MyQuery")
qd.sql = "..."

In debug qd.sql has been updated but the physical MyQuery still contains the old sql.

How to update this physical query ?

The source code given by microsoft here http://msdn.microsoft.com/en-us/library/bb177500.aspx

doesn't work either.

+1  A: 

You should not use SET except with objects. You need an object for QueryDefs, so:

Dim qd As QueryDef
Set qd = CurrentDb.QueryDefs("MyQuery")
qd.SQL = "SELECT Category FROM Categories"

Ensure that the SQL works, or it will error out.

Remou
yes it was a mistypo. But even above doesn't work.My SQL works for sure as it executes when I use DoCmd.RunSQL qd.SQL
Please post the sql
Remou
Are you *sure* the SQL executes correction with RunSQL? If you have SetWarnings turned off, you'll never know if there's an error. The only way to check is to paste the SQL into a new QueryDef in the QBE and try to run that in the QBE.
David-W-Fenton