I was wondering, however. Is it possible to have code that actually
changes a query's SQL code? That could solve my problem. So if the
code is:
SELECT AgeCount010qry.DateYear, AgeCount010qry.Age,
Count(AgeCount010qry.NameID) AS CountOfNameID
FROM AgeCount010qry
GROUP BY AgeCount010qry.DateYear, AgeCount010qry.Age;
Can I change it to:
SELECT AgeCount010qry.DateYear, AgeCount010qry.Age,
Count(AgeCount010qry.NameID) AS CountOfNameID
FROM AgeCount099qry
GROUP BY AgeCount010qry.DateYear, AgeCount010qry.Age;
using a command button?
That is, can the query itself be physically different and if I go in
it, I will see whatever the user "pasted" there last?
Since I have a long query chain which branches off as well, doing any
other suggestion would not work (at this point).
Thanks,
Matt
David C. Holley - 12 Jul 2005 15:06 GMT
It might be possible using the Access Object Model, however I have never
develed into it as the only times that I've dynamically created or
modified a SQL statement has been situations where the SQL statement was
executed via VBA code.
> I was wondering, however. Is it possible to have code that actually
> changes a query's SQL code? That could solve my problem. So if the
[quoted text clipped - 23 lines]
>
> Matt
Brendan Reynolds - 12 Jul 2005 16:43 GMT
You can manipulate the SQL property of a DAO.QueryDef object. For example
...
Private Sub Command0_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("Query2")
If InStr(1, qdf.SQL, "<5") > 0 Then
qdf.SQL = "SELECT Categories.* FROM Categories WHERE
(((Categories.CategoryID)>4));"
Else
qdf.SQL = "SELECT Categories.* FROM Categories WHERE
(((Categories.CategoryID)<5));"
End If
Set qdf = Nothing
Set db = Nothing
DoCmd.OpenQuery "Query2"
End Sub

Signature
Brendan Reynolds (MVP)
>I was wondering, however. Is it possible to have code that actually
> changes a query's SQL code? That could solve my problem. So if the
[quoted text clipped - 23 lines]
>
> Matt
doyle60@aol.com - 13 Jul 2005 15:33 GMT
Thanks. I will give it a try.
Matt