We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

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

ladycoleen
ladycoleen asked
on
Medium Priority
707 Views
Last Modified: 2008-02-01
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
Comment
Watch Question

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...?
SQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:

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

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

Although this is trickiest way to do it.

Author

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 HornSQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015

Commented:
Thanks for the grade.  Good luck with your project.  -Jim
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.