Full Version: Changing Query's SQL string in runtime
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
andreihortua
I have a query by form it's string is built with some user criteria.
Query's name is cnsServiciosAfectados
String's name is stSQLPuertosCanales
Event is cbAnexarATemporal_Click()


Please tell me how to do it
Jack Cowley
I would suggest you take a look at this article and consider using it instead of your current method. It alllows you to leave out criteria or enter criteria in any combination and still work.

Jack
fkegley
Jack, you couldn't do any better than that? LOL
Jack Cowley
Hiya Frank -

Sorry, that is the best that I could do! Let's face it, some days I am better than others...LOL!

Jack
andreihortua
This article is good too.

Let's see...
andreihortua
I've read last article I mentioned, but I see no difference between DAO and ADO.

Which is the difference?
Jack Cowley
The difference is that the code that is supposed to be ADO will not run if you do not have the DAO library checked in References. If you try the code supplied in the article and you do not have the DAO library checked in References you will get an errors and the code will not run...

Jack
andreihortua
Thanks Jack this is what I wanted

Dim dbs As Database, qdf As QueryDef
Set dbs = CurrentDb
dbs.QueryDefs.Delete "cnsServiciosAfectados"
Set qdf = dbs.CreateQueryDef("cnsServiciosAfectados", strSQLPuertosCanales)

Thanks a lot, keep it free.

yayhandclap.gif

See you soon.
Jack Cowley
You are welcome and I am glad you have your code working!

Jack
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.