Change filter property of report in VBA without opening it first.

Is there a way to dynamically through VBA change a reports filter property BEFORE opening it or without using the docmd.openreport report, conditions etc. ? Thank you in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You could set teh SQL source before you open.

Dim mySQL as STring
mySQL = "SELECT * FROM blah ...."

DoCmd.OpenReport "ReportName",,,,,,OpenArgs:=mySQL

Then, in the report on open/format

Me.recordsource = mySQL

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Run the below code anywhere other than the report (will need some editing of course...)

Dim rpt as Report
DoCmd.OpenReport "YourReportName", acViewDesign, , , acHidden
Set rpt = Reports("YourReportName")

With rpt
  .EditAnything = AnyValue   '<--- Whatever you want to change, do it here.
End With

Docmd.Close acReport, "YourReportName"
Set rpt = Nothing


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

You can:
1. Set this in the Report's Record Source query
2. Do an SQL in a Form, then set this as the Report's Record Source
3. Do it "On Format" of the Report

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Alternately, on open of report:
me.filter = yes
Me.Filter = "somefield = " & InputBox("enter desired value")

Although this is trickiest way to do it.
ladycoleenAuthor Commented:
I ended up using a parameterized query for the report using global variables. jimhorn has the best idea, as this code sequences through several parameters, writing the reports in pdf in  specified or dynamically created folders on the network. thanks for all the speedy responses.
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.