How to access query properties in VBA?

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
 
A

Alex Dybenko

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top