473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to filter report using button in Access 2000?

48
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_ClientsHvServices and a report based on that query named Rpt_ClientsHvService. 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 2722
Jim Doherty
897 Expert 512MB
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_ClientsHvServices and a report based on that query named Rpt_ClientsHvService. 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
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 Expert 512MB
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
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_unapproved) based on that query, both has [Program] in it. In the form, I created unbound button where I want to view "rpt_RA_unapproved" 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 Expert 512MB
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_unapproved) based on that query, both has [Program] in it. In the form, I created unbound button where I want to view "rpt_RA_unapproved" 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.OpenReport stDocName, acPreview, , stWhere

it should be

DoCmd.OpenReport 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
Read your code strLinkCriteria is not being passed to the where clause of the openreport command you have

DoCmd.OpenReport stDocName, acPreview, , stWhere

it should be

DoCmd.OpenReport 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 Expert 512MB
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
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 Expert 512MB
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
HowHow
48
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
Hi Jim,
Yes, I placed the calculated control on the report header. When I placed in other places, it won't work...It just shows #Error

I retried and re-read many times since yesterday and finally I know what goes wrong! Sorry I had mislead you with my previous question! I missed to point out this to you and this is very important! Each program is different!
For example, DC (Day Centre) program, we have shopping, outing-weekend, outing-weekday, young people with disability, transport, dementia, aboriginal group..etc. That is why when I choose *DC*, it chose all the clients under Day Centre including "DC-Shopping", "DC-Transport", "DC-Dementia"...etc. This is consider as DC program only but at the same time, they group up differently because they named differently.
In *HACC*, I have HACC-Domestic Assistance, HACC-Social Support, HACC-Transport, HACC-Gardening, HACC-Personal Care...etc. It is only HACC program but it will group differently if I show [Program] because the name is different.

That is why, at first, when I use a query named q_DC_ClientHvSvc. It works.In that query, I have [client name] and [Program] only. Under [Program] field, I use WHERE in "total" and type like *DC* in "criteria". Under [client name], I just have GROUP in "total". Result is, I have 121 client name listed. I created a report using that query and get the correct name list. With this method, I created few more queries, each for one program. And each program here means including different name within that program. I can get the name list for each program correctly because the [program] itself is not showing thus not group by program.

Now, I created a standart query. In that query, I have [client name] and [Program]. I created report using this new query but filter thru the button (which you showed me how to do earlier) so that each button will get the client name list from each program. When I click on the button that takes *DC* client, the client name list is 158 instead of 121 because some of the clients received more than one "activity" in one program. In the report, some of the client name repeated twice or three time depending on the "activity" they receive even though it is still in one program.

If I don't show [Program] field in my query and report, I cannot filter the [Program] using the button from my form. However, when I have [Program] in my query and in my report, my client name list is wrong.

Is there anyway to show or count client's name only once regardless of the "activity" they receive in the program? What should I do next?
Oct 22 '07 #11
Jim Doherty
897 Expert 512MB
Hi Jim,
Yes, I placed the calculated control on the report header. When I placed in other places, it won't work...It just shows #Error

I retried and re-read many times since yesterday and finally I know what goes wrong! Sorry I had mislead you with my previous question! I missed to point out this to you and this is very important! Each program is different!
For example, DC (Day Centre) program, we have shopping, outing-weekend, outing-weekday, young people with disability, transport, dementia, aboriginal group..etc. That is why when I choose *DC*, it chose all the clients under Day Centre including "DC-Shopping", "DC-Transport", "DC-Dementia"...etc. This is consider as DC program only but at the same time, they group up differently because they named differently.
In *HACC*, I have HACC-Domestic Assistance, HACC-Social Support, HACC-Transport, HACC-Gardening, HACC-Personal Care...etc. It is only HACC program but it will group differently if I show [Program] because the name is different.

That is why, at first, when I use a query named q_DC_ClientHvSvc. It works.In that query, I have [client name] and [Program] only. Under [Program] field, I use WHERE in "total" and type like *DC* in "criteria". Under [client name], I just have GROUP in "total". Result is, I have 121 client name listed. I created a report using that query and get the correct name list. With this method, I created few more queries, each for one program. And each program here means including different name within that program. I can get the name list for each program correctly because the [program] itself is not showing thus not group by program.

Now, I created a standart query. In that query, I have [client name] and [Program]. I created report using this new query but filter thru the button (which you showed me how to do earlier) so that each button will get the client name list from each program. When I click on the button that takes *DC* client, the client name list is 158 instead of 121 because some of the clients received more than one "activity" in one program. In the report, some of the client name repeated twice or three time depending on the "activity" they receive even though it is still in one program.

If I don't show [Program] field in my query and report, I cannot filter the [Program] using the button from my form. However, when I have [Program] in my query and in my report, my client name list is wrong.

Is there anyway to show or count client's name only once regardless of the "activity" they receive in the program? What should I do next?
Hi How How,

This can doubtless be sorted and no need to apologise you like all of us can easily make mistakes, however descriptively speaking on here you have lost me I'm afraid. If you PM (private message) me with your email address we can communicate offline and maybe you can send me an empty copy of your database and I'll take a look at it.

There may be a simple adjustment of design that can be had to return what you need but I'm afraid without looking at it my end I'm blind somewhat.

Regards

Jim :)
Oct 22 '07 #12
HowHow
48
Hi How How,

This can doubtless be sorted and no need to apologise you like all of us can easily make mistakes, however descriptively speaking on here you have lost me I'm afraid. If you PM (private message) me with your email address we can communicate offline and maybe you can send me an empty copy of your database and I'll take a look at it.

There may be a simple adjustment of design that can be had to return what you need but I'm afraid without looking at it my end I'm blind somewhat.

Regards

Jim :)
Thank you! Finally I got it! The Function works fine and my mistake was didn't take out the date, and service type...etc.
Only after I removed every field, left only [client name] and [ProgramGroup], it grouped up as what I need. Thanks again Jim! You are very kind and helpful!

Just to share the function with others if they need it.

Expand|Select|Wrap|Line Numbers
  1. Public Function ProgramType(strProgram As String)
  2.  
  3. On Error Resume Next
  4. If InStr(strProgram, "-DC-") > 0 Then
  5. ProgramType = "DC"
  6. End If
  7.  
  8. ' Group the program that has the word *DC* to DC
  9.  
  10. End Function
And in query, call the function by typing the below in field:

Expand|Select|Wrap|Line Numbers
  1. ProgramType: ProgramType([Program])
Oct 23 '07 #13

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

Similar topics

0
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...
3
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...
8
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...
16
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...
5
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...
1
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...
4
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...
5
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...
3
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.