473,396 Members | 2,106 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,396 software developers and data experts.

how to filter report based on the list you selected from listbox in a form?

180 100+
I want to filter report to show only field you selected from a listbox in a form.
For example I have query which field are ID, Ni, Fe, Mg and Sc
The field ID is primary key. it has value of 1 meaning first record. then the value of field Ni is 50, Fe is 49, Mg is 1.124 and Sc is 3.014. I have a listbox in a form which name is listfilter, then it's row source type is field list which shows;
ID
Ni
Fe
Mg
Sc
then I have command button in form that when you click, it shows report. If I didn't select anything in listbox then the report must show none, but when I select Ni, it must show only Ni.
How can I do this?
Apr 16 '16 #1

✓ answered by PhilOfWalton

I'm going to make some assumptions as the information given is a little sparse.
I assume you have a table of Elements something like
ElememntID
ElememntName
ElementSymbol

I am assuming your list box is bound to
SELECT Elements.ElementSymbol, Elements.ElementName FROM Elements ORDER BY Elements.ElementSymbol;
and the bound column is 1 and it is a Simple MultiSelect box

In this example the form is Form3 and the List Box is List3 and the report is RptElements

Expand|Select|Wrap|Line Numbers
  1. Private Sub PrintIt_Click()
  2.  
  3.     Dim stDocCriteria As String
  4.     Dim VarItem As Variant
  5.  
  6.     For Each VarItem In Forms!Form3!List3.ItemsSelected
  7.         stDocCriteria = stDocCriteria & "ElementSymbol = " & Chr$(34) & Forms!Form3!List3.ItemData(VarItem) & Chr$(34) & " OR "
  8.     Next VarItem
  9.     If stDocCriteria <> "" Then
  10.         stDocCriteria = Left(stDocCriteria, Len(stDocCriteria) - 4)
  11.     Else
  12.         stDocCriteria = "True"
  13.     End If
  14.  
  15.     DoCmd.OpenReport "RptElements", acViewPreview, , stDocCriteria
  16.  
  17. End Sub
  18.  
Hope that helps

Phil

6 5232
Seth Schrock
2,965 Expert 2GB
So, just to clarify, are you wanting to filter rows or fields? I think that you are meaning filtering fields. If I'm correct, is it possible to select multiple fields in the listbox? This would change how it would be done.

If you only want a report to show if something is selected in your listbox, then you need to add that check to your button's OnClick event.
Apr 16 '16 #2
eneyardi
180 100+
if possible to select multiple fields in a listbox so that based on your selected fields in listbox, thats only the fields that report will show. or If it can be done by checkbox then how to do it?
Apr 16 '16 #3
PhilOfWalton
1,430 Expert 1GB
I'm going to make some assumptions as the information given is a little sparse.
I assume you have a table of Elements something like
ElememntID
ElememntName
ElementSymbol

I am assuming your list box is bound to
SELECT Elements.ElementSymbol, Elements.ElementName FROM Elements ORDER BY Elements.ElementSymbol;
and the bound column is 1 and it is a Simple MultiSelect box

In this example the form is Form3 and the List Box is List3 and the report is RptElements

Expand|Select|Wrap|Line Numbers
  1. Private Sub PrintIt_Click()
  2.  
  3.     Dim stDocCriteria As String
  4.     Dim VarItem As Variant
  5.  
  6.     For Each VarItem In Forms!Form3!List3.ItemsSelected
  7.         stDocCriteria = stDocCriteria & "ElementSymbol = " & Chr$(34) & Forms!Form3!List3.ItemData(VarItem) & Chr$(34) & " OR "
  8.     Next VarItem
  9.     If stDocCriteria <> "" Then
  10.         stDocCriteria = Left(stDocCriteria, Len(stDocCriteria) - 4)
  11.     Else
  12.         stDocCriteria = "True"
  13.     End If
  14.  
  15.     DoCmd.OpenReport "RptElements", acViewPreview, , stDocCriteria
  16.  
  17. End Sub
  18.  
Hope that helps

Phil
Apr 16 '16 #4
eneyardi
180 100+
thank u philhalton, that really helps. I just need to modify it more. thanks.
Apr 17 '16 #5
Seth Schrock
2,965 Expert 2GB
The solution that Phil gave filters records, not fields. Is this what you are looking for? Based on post #3, I thought that you were trying to only show certain fields, not certain records that had something in certain fields.
Apr 17 '16 #6
NeoPa
32,556 Expert Mod 16PB
Eneyardi has had his account suspended for two weeks due to persistent failure to post in a reasonable manner. They are very careless of details and others' time.

This thread, which was also double-posted, is a good example of how much time and efforts are wasted trying to deal with such carelessness.

NB. This isn't a matter of a foreign user struggling, as indicated clearly by his failure even to get PhilOfWalton's name right when responding.
Apr 18 '16 #7

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

Similar topics

3
by: Richard | last post by:
Hi, I have a form based on a table. When I filter the form I want to run a report based on the same table with the same filter as the form. No problem until I want to filter a combo box where...
1
by: davidbennett | last post by:
Hello, I am new to MS Access. I have created a series of forms that users access to perform data entry. I now need to build in reporting functionality. I would like to create a form that has a...
1
by: fleece | last post by:
I have a continuous form based on some selected criteria. Now I want to send the search results to a report. How could I do that? It's better if I could sort the results before export to report. ...
5
by: favor08 | last post by:
have a mainform called PendingsMain and a subform called PendingsSub. You can filter the subform by different filters and this works fine. i want to create a report that will print out the...
94
by: mlcampeau | last post by:
I have a report (JobVacanciesOnly) that has a subreport (JobVacanciesOnlySR) that are based on two separate queries. MY - JobVacancyJobs SELECT Job.Code, Job.Title, Job.Grade, Grade.Minimum,...
6
by: pouj | last post by:
what i want to do is basically have form where my selection in the combox make the diffrence with what the form reports. this is what the underlying informaion is.... software is access 2007 i...
1
by: rkm2 | last post by:
I currently have a form "UserSearchForm" which allows a user to select values from several different unbound combo boxes in the header section and press a search command which filters the list in the...
0
by: munkee | last post by:
Hi all, This would normally be quite simple however for some reason I can not getting working. My code to open my report filtered to a primary key is as follows: Case "Full record"...
1
by: Neobeowulf | last post by:
Team, I'm totally stumped on this one. I'm trying to create a button called "Run Report" that opens a report based off a selection made in a combo box then filtered by a column in the report...
5
by: shawnrye1980 | last post by:
I have a table that has 15 managers and I have queries that I need for there employees I have 5 union all queries because there are too many where clauses, I have done this and based off the main...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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...
0
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,...

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.