Solved

Trying to open a report with a filter

Posted on 2016-11-23
2
36 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 35

Accepted Solution

by:
PatHartman earned 500 total points
ID: 41899322
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
ID: 41899335
Perfect.  Thank you.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you 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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

809 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