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?
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 -
Private Sub PrintIt_Click()
-
-
Dim stDocCriteria As String
-
Dim VarItem As Variant
-
-
For Each VarItem In Forms!Form3!List3.ItemsSelected
-
stDocCriteria = stDocCriteria & "ElementSymbol = " & Chr$(34) & Forms!Form3!List3.ItemData(VarItem) & Chr$(34) & " OR "
-
Next VarItem
-
If stDocCriteria <> "" Then
-
stDocCriteria = Left(stDocCriteria, Len(stDocCriteria) - 4)
-
Else
-
stDocCriteria = "True"
-
End If
-
-
DoCmd.OpenReport "RptElements", acViewPreview, , stDocCriteria
-
-
End Sub
-
Hope that helps
Phil
6 5232
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.
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?
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 -
Private Sub PrintIt_Click()
-
-
Dim stDocCriteria As String
-
Dim VarItem As Variant
-
-
For Each VarItem In Forms!Form3!List3.ItemsSelected
-
stDocCriteria = stDocCriteria & "ElementSymbol = " & Chr$(34) & Forms!Form3!List3.ItemData(VarItem) & Chr$(34) & " OR "
-
Next VarItem
-
If stDocCriteria <> "" Then
-
stDocCriteria = Left(stDocCriteria, Len(stDocCriteria) - 4)
-
Else
-
stDocCriteria = "True"
-
End If
-
-
DoCmd.OpenReport "RptElements", acViewPreview, , stDocCriteria
-
-
End Sub
-
Hope that helps
Phil
thank u philhalton, that really helps. I just need to modify it more. thanks.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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. ...
|
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...
|
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,...
|
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...
|
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...
|
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"...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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,...
|
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: 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,...
| |