How to access query properties in VBA?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I run a query with the following code:

Dim stDocName As String
stDocName = "qry_toRun"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Now I want to set the Filter property before running. Something like:

qry_toRun.Filter = "anyVar < 10"

But that doesn't work. What is the proper code?

Thanks for help

Henk
 
hi,
you can access query sql like this:

strSQL=currentdb.querydefs("qry_toRun").SQL
strSQL=strSQL & " WHERE anyVar < 10"

currentdb.querydefs("qry_toRun").SQL=strSQL

DoCmd.OpenQuery stDocName, acNormal, acEdit

of course, if you already have WHERE in a query - you need to add " AND
....", or just completely build whole SQL

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com
 
Back
Top