Solved

Trying to open a report with a filter

Posted on 2016-11-23
2
16 Views
Last Modified: 2016-11-23
I have this code in the onclick code of a command button on a form...

    Me.Filter = "ListApptBestAgentBusiness" = -1
    Me.FilterOn = True
    
    DoCmd.OpenReport "rptListingAppointmentsSet", acViewPreview, "", "", acNormal

Open in new window


The report is supposed to be displaying only the records where ListApptBestAgentBusiness is True

But it is displaying all records and not filtering.  Thoughts?
0
Comment
Question by:SteveL13
2 Comments
 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
Comment Utility
You are applying the filter to the form that is opening the report, not the report itself.  The report isn't even open yet.  The OpenReport method has two arguments.  One for a filter and the other for a where clause.  The Where clause is more efficient if your BE is connected to a RDBMS since it returns only the selected records and so can minimize network traffic.  The filter option returns ALL records requested by the report's RecordSource and then filters them locally.  So, depending on the size of the recordset the Where clause could save a lot of time.  Personally, I always use the Where Clause regardless of what type of tables I am connected to.

DoCmd.OpenReport "rptListingAppointmentsSet", acViewPreview, , "ListApptBestAgentBusiness = -1", acNormal
0
 

Author Closing Comment

by:SteveL13
Comment Utility
Perfect.  Thank you.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now