Is there any way to change the query that is run for a report through VBA?
Currently a report of mine runs a certain query to populate the report. Depending on certain conditions, I want to change the query that is used for that report.
Printable View
Is there any way to change the query that is run for a report through VBA?
Currently a report of mine runs a certain query to populate the report. Depending on certain conditions, I want to change the query that is used for that report.
Also, does the Order By clause not work for reports? I have it in my query and if you run the query seperately, it works fine. But when I use the query with a function, it doesn't put them in order.
How are you making your queries? In Access or through building SQL in VB code? I have a project where some queries are created in Access, put in a macro, which is then invoked by code as well.
Wouldn't it be easier to write your own apps instead of dealing with others code? I know it would be for me.
I'm building the queries in SQL through the VBA editor.
I've solved the first two problems, but now I'm having another problem... after I create the SQL statement, I write it out to a query so that it can be used by the "DoCmd.OpenReport" call. But whenever it writes the Access query, it puts extra parenthesis "()" around the query and then it doesn't work right. If I go into the query and delete the outermost parenthesis, the query works fine. But I have to create it on the fly and the stupid thing keeps putting those "()" in there.
:mad:
Are you adding parantheses when you build the query? If so, try leaving a pair off. I've noticed that if you use the design view to build a query, Access throws a bunch of parantheses in when you look at the query in SQL view.
I'm not putting any parens in when I create the statement. It puts them all in by itself and hence screws up my report!
Nevermind, I got it :D
Stupid Access is f-ing picky. :eek: