View Full Version : Change a Query fields criteria in VBA


Smee
08-08-2005, 07:44 AM
Hey All,

I've had a search for the last hour, but I haven't found anything for this topic. :confused:

I have a query def (qdf) setup for query1

I want to change the criteria part of qdf.fields(0) from:

=date() -1
to
=date() - x : x will change in the code.

I was hoping for something like qdf.fields(0).criteria but that doesn't exist (unless I have a missing reference).

Any ideas?

Thanks

Pat Hartman
08-08-2005, 06:23 PM
You can change the criteria to:
=Date() - [some name]

If you run the query in VBA, you will need to provide the parameter value using this technique:
http://www.access-programmers.co.uk/forums/showthread.php?s=&postid=176367#post176367

If you are using the query as a RecordSource, it is best to refer to a form field:
=Date() - Forms!yourformname!yourcontrolname

Smee
08-11-2005, 03:53 AM
Thanks Pat - excellent as always :)

NFJ
11-05-2007, 04:12 PM
Hey Smee--could you post an example of the code you're using? I'm pretty new to VBA in Access (I'm familiar with using it in Excel), and could use some pointers. It sounds like what you're doing is very similar to what I'd like to do (use a userform to alter Report queries). Do you mind sharing the wealth?

Thanks!

-NFJ