473,670 Members | 2,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to filter report using button in Access 2000?

48 New Member
I need to create a few reports using one query and I wish to do the program filter from the buttons in a form. I had created a query named q_ClientsHvServ ices and a report based on that query named Rpt_ClientsHvSe rvice. In the main form, I created few buttons to view clients from different progrom. When I click on a button named "HACC", the report should select all the clients that have services under PROGRAM starting with HA (and all HA*). When I click on a button named "CACP", the report should select all the clients starting with "CAC" program. Is it possible?

How should I write the filter based on the click on the buttons?

My code on my "All client" button are as follow:

Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_OpenALLClientsHvSvc_Click()
  2. On Error GoTo Err_btn_OpenALLClientsHvSvc_Click
  3.  
  4.     Dim stDocName As String
  5.  
  6.     stDocName = "Rpt_ClientsHvService"
  7.     DoCmd.OpenReport stDocName, acPreview
  8.  
  9. Exit_btn_OpenALLClientsHvSvc_Click:
  10.     Exit Sub
  11.  
  12. Err_btn_OpenALLClientsHvSvc_Click:
  13.     MsgBox Err.Description
  14.     Resume Exit_btn_OpenALLClientsHvSvc_Click
  15.  
  16. End Sub
Oct 11 '07 #1
12 2735
Jim Doherty
897 Recognized Expert Contributor
I need to create a few reports using one query and I wish to do the program filter from the buttons in a form. I had created a query named q_ClientsHvServ ices and a report based on that query named Rpt_ClientsHvSe rvice. In the main form, I created few buttons to view clients from different progrom. When I click on a button named "HACC", the report should select all the clients that have services under PROGRAM starting with HA (and all HA*). When I click on a button named "CACP", the report should select all the clients starting with "CAC" program. Is it possible?

How should I write the filter based on the click on the buttons?

My code on my "All client" button are as follow:

Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_OpenALLClientsHvSvc_Click()
  2. On Error GoTo Err_btn_OpenALLClientsHvSvc_Click
  3.  
  4. Dim stDocName As String
  5.  
  6. stDocName = "Rpt_ClientsHvService"
  7. DoCmd.OpenReport stDocName, acPreview
  8.  
  9. Exit_btn_OpenALLClientsHvSvc_Click:
  10. Exit Sub
  11.  
  12. Err_btn_OpenALLClientsHvSvc_Click:
  13. MsgBox Err.Description
  14. Resume Exit_btn_OpenALLClientsHvSvc_Click
  15.  
  16. End Sub

You need to build your criteria string for the WHERE clause of the openreport argument so that it knows the records to return as part of the report

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim stDocName As String
  3.     Dim stLinkCriteria As String
  4.     stDocName = "Rpt_ClientsHvService"
  5.  
  6. stLinkCriteria = "[PROGRAM] Like 'HACC*'"
  7.  
  8. DoCmd.OpenReport stDocName, acPreview, , stWhere
  9.  
I am sure you can adapt this to fit your fieldnames and other requirements .

For versatility you might want to look at referencing a selectable value from a form control as well, because hard coded like this it only does ONE thing (which may suit your purpose of course I don't know)

Regards

Jim :)
Oct 11 '07 #2
HowHow
48 New Member
You need to build your criteria string for the WHERE clause of the openreport argument so that it knows the records to return as part of the report

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim stDocName As String
  3.     Dim stLinkCriteria As String
  4.     stDocName = "Rpt_ClientsHvService"
  5.  
  6. stLinkCriteria = "[PROGRAM] Like 'HACC*'"
  7.  
  8. DoCmd.OpenReport stDocName, acPreview, , stWhere
  9.  
I am sure you can adapt this to fit your fieldnames and other requirements .

For versatility you might want to look at referencing a selectable value from a form control as well, because hard coded like this it only does ONE thing (which may suit your purpose of course I don't know)

Regards

Jim :)

I still can't get it right. Is it because I don't have [Program] in my report? Does the code control the [Program] on Query?

My purpose is to know the number of the client received service from particular program and get a client name list from that result. If I put [Program] to my Report, the client numbers will be more than what I expected because it group by program and then by client's name. Well, I had tried to put [Program] to report and tested on the code, the report gave all the clients from all the program. The code is as below, can you spot where goes wrong?

Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_OpenALLClientHasSvc_Click()
  2. On Error GoTo Err_btn_OpenALLClientHasSvc_Click
  3.  
  4.  
  5.     Dim stDocName As String
  6.     Dim stLinkCriteria As String
  7.     stDocName = "Rpt_ClientHasService"
  8.     stLinkCriteria = "[Program] like 'HA*' "
  9.  
  10.     DoCmd.OpenReport stDocName, acPreview, , stWhere
  11.  
  12. Exit_btn_OpenALLClientHasSvc_Click:
  13.     Exit Sub
  14.  
  15. Err_btn_OpenALLClientHasSvc_Click:
  16.     MsgBox Err.Description
  17.     Resume Exit_btn_OpenALLClientHasSvc_Click
  18.  
  19. End Sub

Previously I created query for each program, then created reports based on the queries. It is accurate but I found too many queries and reports to maintan everytime something changed. So I am thinking of using one standard Query and one standard Report but control the program filter in Query thru button that has Program caption in Form.

What should I do to control the filter in Query from Form (button) so that I will get the correct Report? Is it possible?
Oct 12 '07 #3
Jim Doherty
897 Recognized Expert Contributor
I still can't get it right. Is it because I don't have [Program] in my report? Does the code control the [Program] on Query?

My purpose is to know the number of the client received service from particular program and get a client name list from that result. If I put [Program] to my Report, the client numbers will be more than what I expected because it group by program and then by client's name. Well, I had tried to put [Program] to report and tested on the code, the report gave all the clients from all the program. The code is as below, can you spot where goes wrong?

Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_OpenALLClientHasSvc_Click()
  2. On Error GoTo Err_btn_OpenALLClientHasSvc_Click
  3.  
  4.  
  5. Dim stDocName As String
  6. Dim stLinkCriteria As String
  7. stDocName = "Rpt_ClientHasService"
  8. stLinkCriteria = "[Program] like 'HA*' "
  9.  
  10. DoCmd.OpenReport stDocName, acPreview, , stWhere
  11.  
  12. Exit_btn_OpenALLClientHasSvc_Click:
  13. Exit Sub
  14.  
  15. Err_btn_OpenALLClientHasSvc_Click:
  16. MsgBox Err.Description
  17. Resume Exit_btn_OpenALLClientHasSvc_Click
  18.  
  19. End Sub

Previously I created query for each program, then created reports based on the queries. It is accurate but I found too many queries and reports to maintan everytime something changed. So I am thinking of using one standard Query and one standard Report but control the program filter in Query thru button that has Program caption in Form.

What should I do to control the filter in Query from Form (button) so that I will get the correct Report? Is it possible?

Hi HowHow :)

With the greatest of respect read your original post you said

"select all the clients that have services under PROGRAM starting with HA"

From that I can only assume that PROGRAM is a fieldname in your table or query and that it is this that you are going to compare in returning a dataset where the PROGRAM contains data starting with HA...hence the LIKE operand.

The logic in all of this is to return datasets based on comparisons you make against fielded data using the WHERE clause of an SQL statement.

So......

SELECT * FROM tblMyData WHERE [Surname]='Jones'"
returns everyone who has a surname of Jones

SELECT * FROM YourTableName WHERE [Program]='Rusty Car' AND [Service]='15,000,000 miles'
returns all cars that either need scrapping or awarding a congratulatory certificate of longevity.

The code displayed for the report is correct! in that it 'would' open a report where and IF a field existed on there called PROGRAM and where the field starts with HA.

You build your reports around your tables or queries and you call your reports restricting any data it returns by using the WHERE clause of the openreport method as displayed

Query by FORM or QBF as it is known in short terms from your perspective is an accepted method of calling a report and supplying criteria to it from FORM controls where you have picked or entered your criteria into the form (usually unbound) upon which the report will rely when it is opened.

If this is what you are wanting then yes it can be done. there are lots of references to the query by form methodology for you to research

Jim :)
Oct 12 '07 #4
HowHow
48 New Member
Hi HowHow :)

With the greatest of respect read your original post you said

"select all the clients that have services under PROGRAM starting with HA"

From that I can only assume that PROGRAM is a fieldname in your table or query and that it is this that you are going to compare in returning a dataset where the PROGRAM contains data starting with HA...hence the LIKE operand.

The logic in all of this is to return datasets based on comparisons you make against fielded data using the WHERE clause of an SQL statement.

So......

SELECT * FROM tblMyData WHERE [Surname]='Jones'"
returns everyone who has a surname of Jones

SELECT * FROM YourTableName WHERE [Program]='Rusty Car' AND [Service]='15,000,000 miles'
returns all cars that either need scrapping or awarding a congratulatory certificate of longevity.

The code displayed for the report is correct! in that it 'would' open a report where and IF a field existed on there called PROGRAM and where the field starts with HA.

You build your reports around your tables or queries and you call your reports restricting any data it returns by using the WHERE clause of the openreport method as displayed

Query by FORM or QBF as it is known in short terms from your perspective is an accepted method of calling a report and supplying criteria to it from FORM controls where you have picked or entered your criteria into the form (usually unbound) upon which the report will rely when it is opened.

If this is what you are wanting then yes it can be done. there are lots of references to the query by form methodology for you to research

Jim :)

Hi Jim :),
Sorry for the unclear question previously.You are right that [Program] is in my table as well as in the query, however, it wasn't show in my report because I have "WHERE" in my query and I cannot tick "show" box.

Please forget about my previous set up. Now I had created a new query (called q_RA_unapproved ), and a new report (called rpt_RA_unapprov ed) based on that query, both has [Program] in it. In the form, I created unbound button where I want to view "rpt_RA_unappro ved" by program. However, the code below still doesn't work. It brings all the unapproved service from all the programs instead of the specific program I want.

Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_CACP_RA_unapproved_Click()
  2. On Error GoTo Err_btn_CACP_RA_unapproved_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = "rpt_RA_unapproved"
  8.     stLinkCriteria = "[Program] like ' *C.A.C* ' "
  9.     DoCmd.OpenReport stDocName, acPreview, , stWhere
  10.  
  11.  
  12. Exit_btn_CACP_RA_unapproved_Click:
  13.     Exit Sub
  14.  
  15. Err_btn_CACP_RA_unapproved_Click:
  16.     MsgBox Err.Description
  17.     Resume Exit_btn_CACP_RA_unapproved_Click
  18.  
  19. End Sub
Can you help spot where goes wrong? appreciate your time... :)
Oct 15 '07 #5
Jim Doherty
897 Recognized Expert Contributor
Hi Jim :),
Sorry for the unclear question previously.You are right that [Program] is in my table as well as in the query, however, it wasn't show in my report because I have "WHERE" in my query and I cannot tick "show" box.

Please forget about my previous set up. Now I had created a new query (called q_RA_unapproved ), and a new report (called rpt_RA_unapprov ed) based on that query, both has [Program] in it. In the form, I created unbound button where I want to view "rpt_RA_unappro ved" by program. However, the code below still doesn't work. It brings all the unapproved service from all the programs instead of the specific program I want.

Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_CACP_RA_unapproved_Click()
  2. On Error GoTo Err_btn_CACP_RA_unapproved_Click
  3.  
  4. Dim stDocName As String
  5. Dim stLinkCriteria As String
  6.  
  7. stDocName = "rpt_RA_unapproved"
  8. stLinkCriteria = "[Program] like ' *C.A.C* ' "
  9. DoCmd.OpenReport stDocName, acPreview, , stWhere
  10.  
  11.  
  12. Exit_btn_CACP_RA_unapproved_Click:
  13. Exit Sub
  14.  
  15. Err_btn_CACP_RA_unapproved_Click:
  16. MsgBox Err.Description
  17. Resume Exit_btn_CACP_RA_unapproved_Click
  18.  
  19. End Sub
Can you help spot where goes wrong? appreciate your time... :)
Read your code strLinkCriteria is not being passed to the where clause of the openreport command you have

DoCmd.OpenRepor t stDocName, acPreview, , stWhere

it should be

DoCmd.OpenRepor t stDocName, acPreview, , stLinkCriteria

You created criteria yes and assigned a variable to it but are not passing it the the command correctly

Regards

Jim
Oct 15 '07 #6
HowHow
48 New Member
Read your code strLinkCriteria is not being passed to the where clause of the openreport command you have

DoCmd.OpenRepor t stDocName, acPreview, , stWhere

it should be

DoCmd.OpenRepor t stDocName, acPreview, , stLinkCriteria

You created criteria yes and assigned a variable to it but are not passing it the the command correctly

Regards

Jim
Thank you! This is a big help! Now I can stop creating lots of queries and reports (for each program) now! yeah!

I guess I have no way to do the same if the field is not in the report even though the field [Program] is in my query and table. When I put the [Program] to the report, the total number of client is wrong because a client can have more than one program. I only want to have each client counted once and produce a non duplicate name list.
Oct 16 '07 #7
Jim Doherty
897 Recognized Expert Contributor
Thank you! This is a big help! Now I can stop creating lots of queries and reports (for each program) now! yeah!

I guess I have no way to do the same if the field is not in the report even though the field [Program] is in my query and table. When I put the [Program] to the report, the total number of client is wrong because a client can have more than one program. I only want to have each client counted once and produce a non duplicate name list.
Group your Report by Client in the report itself. Look at Report sorting and grouping

Jim
Oct 16 '07 #8
HowHow
48 New Member
Group your Report by Client in the report itself. Look at Report sorting and grouping

Jim
I had tried few times but still didn't get it. Even recreate my query and report...Really lost already!
When I have [Program] in both of my query and report, the report is group by both [Program] and client's name. For example, when a client received 3 programs many times from Jan to June, the report show client's name three times and each with a program beside (different program). Thus my text box with
Expand|Select|Wrap|Line Numbers
  1. =Count([Name]) 
total up the same client as 3 instead of 1. My name list should be one client but end up with 3 same name. Even after I make the [Program] invisible in report, it still does the same thing. Need your advise again please...thanks !
Oct 17 '07 #9
Jim Doherty
897 Recognized Expert Contributor
I had tried few times but still didn't get it. Even recreate my query and report...Really lost already!
When I have [Program] in both of my query and report, the report is group by both [Program] and client's name. For example, when a client received 3 programs many times from Jan to June, the report show client's name three times and each with a program beside (different program). Thus my text box with
Expand|Select|Wrap|Line Numbers
  1. =Count([Name]) 
total up the same client as 3 instead of 1. My name list should be one client but end up with 3 same name. Even after I make the [Program] invisible in report, it still does the same thing. Need your advise again please...thanks !
If you are grouping by client do you have the headers and footers displayed in your report for the client? if not do so and place any calculated control within the header or footer, that way your count function will count on that grouping only if I am reading you correctly.

Regards

Jim
Oct 17 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
6468
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the report are based on the same View addressed in the Record Source of both as 'dbo.CLMain_vw'. The View resides in a SQL Server 2000 database. There are two different problems I am having with filtering: The first involves filtering in the form by date...
3
3780
by: Baz'noid | last post by:
Hi all, With the recent postal strikes here in the UK i'm trying to persuade access to email reports at the touch of a button. I've not been able to figure out how to filter the report - when i print a report via a button i have it filtering to just the customer and invoice on the form on screen, but when i email, it uses the customer details on screen for the email address but produces a separate HTML file for EVERY customer on the...
8
6530
by: dick | last post by:
I am just trying to print/report the results of a "filter by selection" which is done by right-clicking a form, filling in values, and "applying the filter." I have searched the newsgroups, and there are many examples. BUT, they fail sometimes. The techique is to pass the form's Me.filter as the "where condition" in a Docmd.openreport statement in code behind a "print button" on the form.
16
18407
by: Nhmiller | last post by:
I already have a report designed under Reports. When I use filtering in Forms or Tables, I see no way to select that filtered list when I am in Reports, and there appears to be no way to do the filtering when I am in Reports. I have received two replies to this message, posted a few days ago within another Subject. One requires making programming type statements. That should not be necessary -- Access must have a quick way to just click...
5
3274
by: dkelly925 | last post by:
Is there a way to add an If Statement to the following code so if data in a field equals "x" it will launch one report and if it equals "y" it would open another report. Anyone know how to modify this? Private Sub cmdPreview_Click() On Error GoTo Err_Handler 'Purpose: Open the report filtered to the items selected in the list box. 'Author: Allen J Browne, 2004. http://allenbrowne.com Dim varItem As Variant 'Selected items
1
16376
by: lorirobn | last post by:
Hi, I have a report that works just fine. Now I would like to add the capability to choose selection criteria to limit what is displayed. I created several reports that do this, but they used VBA to create SQL statements, then apply them. Now that I have been using Access/VBA for awhile, I am wondering if there is a simpler way to do this than coding these long sql statements. My report has a query as its record source. Can I just...
4
4515
by: Fran | last post by:
I recently tried to use code for "Use a multi-select list box to filter a report" from Allen Browne in my database. I was able to add the code and adapt it to my needs, however I am getting an error. I click Ok and the report opens. I look in the design view and the filter is there but the IN equals "" (it is blank, the values are not in there)
5
2164
by: Whasigga | last post by:
Hi guys I've got a report that I have created. It is based off of a query that I made. I use it to show different combinations of data, but its the same type of information... It is called from 5 buttons on a form. each of the buttons opens the report to show something different, most are just the time frame of the data, whether it be 1 day, 1 week, 1 month, 1 year... Each one uses the doCmd.OpenReport method, and then passes a Where...
3
2662
by: franc sutherland | last post by:
Hello, I have a report which I filter using the me.filter command in the OnOpen event. Me.Filter = "OrderID=" & Forms!variable_form_name! Me.FilterOn = True I want to be able to open that report, filtered, from different forms. How do I carry the name of the current form into the
0
8384
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8813
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7412
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6212
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4388
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2799
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.