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
ladycoleenAsked:
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.

dannywarehamCommented:
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


Idea...?
0
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

0

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
jjafferrCommented:

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

jaffer
0
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.

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

Although this is trickiest way to do it.
0
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.
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
0
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.