473,386 Members | 1,830 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.

Filter FormTable to show only "Yes" from Yes/No BOX

7
Hello there!

I am running into Trouble with my current database.

I have a table with "Services"

I then made a FormTable that lists all of them.

Each "Service" has a field called "Erledigt" (German)

This is a Yes/no Field.

I have made a button - This button is supposed to be clicked and then only Show the ones that are ticked "Yes" and then back to the original when clicked once again, is this possible??

Kind Regards
Anders
Feb 24 '15 #1

✓ answered by twinnyfo

Try something like this in the module for your form:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private fFilter As Boolean
  5.  
  6. Private Sub cmdFilter_Click()
  7.     Me.Filter = "Erledigt = " & _
  8.         IIf(fFilter, "True", "False")
  9.     Me.FilterOn = True
  10.     fFilter = not fFilter
  11. End Sub
Tschüss!

12 4080
twinnyfo
3,653 Expert Mod 2GB
Try something like this in the module for your form:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private fFilter As Boolean
  5.  
  6. Private Sub cmdFilter_Click()
  7.     Me.Filter = "Erledigt = " & _
  8.         IIf(fFilter, "True", "False")
  9.     Me.FilterOn = True
  10.     fFilter = not fFilter
  11. End Sub
Tschüss!
Feb 24 '15 #2
iskov
7
Vielen Dank, dass war sehr erfolgreich!!!!
;-)
Feb 24 '15 #3
iskov
7
@Twinny

If I want to add a msgbox to say "filtered for 'erledigt'." and "Filtered for None-'erledigt'" where do I put the msgbox's??

Kind Regards
Feb 24 '15 #4
twinnyfo
3,653 Expert Mod 2GB
I would recommend changing the Caption on the Command Button:

Expand|Select|Wrap|Line Numbers
  1. Me.cmdFilter.Caption = IIf(fFilter, "Un-Filter", "Filter")
between lines 6 and 7....
Feb 24 '15 #5
iskov
7
Thank you once again, I like the idea alot!
Feb 24 '15 #6
twinnyfo
3,653 Expert Mod 2GB
Glad I could be of assistance!
Feb 24 '15 #7
iskov
7
I am going to pump this post as I am running into a minor Problem.

Basically the Report button works perfectly, however my form ALSO has a search field:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Befehl104_Click()
  2. Dim strsearch As String
  3. Dim strText As String
  4. Dim filterstr As String
  5.  
  6. If (Len(Txtsearch.Value) > 0) Then
  7.     strText = Me.Txtsearch.Value
  8.     strsearch = "SELECT * from ServiceAuftragTabelleQ where ((Unternehmen like ""*" & strText & "*"") or (NiederlassungName like ""*" & strText & "*"") or (AuftragAxapta like ""*" & strText & "*"") or (AuftragKunde like ""*" & strText & "*"") or (Typ like ""*" & strText & "*"") or (Art like ""*" & strText & "*"") or (DatumAngelegt like ""*" & strText & "*"") or (DatumEinsatzGeplant like ""*" & strText & "*"") or (AnsprechspartnerKunde like ""*" & strText & "*"") or (AnsprechspartnerITEC like ""*" & strText & "*"") or (ServicemitarbeiterITEC like ""*" & strText & "*""))"
  9.     Me.RecordSource = strsearch
  10. Else
  11.     strsearch = "SELECT * from ServiceAuftragTabelleQ"
  12.     Me.RecordSource = strsearch
  13. End If
  14.  
  15. Me.Filter = "Erledigt = " & _
  16.    IIf(fFilter, "False or True", "False")
  17. Me.FilterOn = True
  18. End Sub
The searchfield has the above showed button connected.

This allows me to search for words in all of my different informations for every Service contract in my table.

However if I for instance search for customer "Danish Crown" the Report button will still only Show all of the "Erledigt" or both if I have the filter activated or not:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Befehl101_Click()
  2. Me.Befehl101.Caption = IIf(fFilter, "Alle anzeigen", "Nur offene anzeigen")
  3.      Me.Filter = "Erledigt = " & _
  4.          IIf(fFilter, "False", "False or True")
  5.      Me.FilterOn = True
  6.      fFilter = Not fFilter
  7.  
  8. End Sub
  9.  
That is the filter button, and this is what the Report button Looks like at the Moment:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Befehl109_Click()
  2. Dim strWhere As String
  3.  If Me.Dirty Then Me.Dirty = False
  4.  If Me.FilterOn Then strWhere = Me.Filter
  5.  DoCmd.OpenReport "ServiceAufträgeR", acViewPreview, , strWhere
  6. End Sub
  7.  
If anything is unclear, please feel free to ask!

Anders Iskov
Mar 2 '15 #8
twinnyfo
3,653 Expert Mod 2GB
Anders,

First, one question per thread, please, as this allows other users to search for answers more easily.

Second, be sure when you post code on the forum that you use Code Tags (highlight your desired text and then click the "[CODE/]" button.

Third, I'm not exactly sure what your question is in the above. Some of it may have to do with the mixture of English and German in the code. Also, looking back at my code in Post #2, I see in line 8, it should read:

Expand|Select|Wrap|Line Numbers
  1. IIf(fFilter, True, False)
Notice the lack of quotes around the True and False Values. This may be setting off your filter issues.
Mar 2 '15 #9
iskov
7
I am sorry, I have changed the codes so they are alittle easier to look at.

Should I make a new thread?

My Problem is basically:

The Report-filter works perfectly fine along with the button that filters for "erledigt" or "non-erledigt" HOWEVER when I use my search field (txtsearch) with the button to search with, the Report still only Shows ALL of the erledigt or ALL of the non-erledigt. I would preferably be able to look up a customer (that has several Service contracts) and ONLY print those out.

I much appriciate the help I have gotten so far, and I do not want to break any Forum rules, I just thought I would get an easier answer when I posted in the same thread.

Anders Iskov
Mar 2 '15 #10
twinnyfo
3,653 Expert Mod 2GB
I think what you are asking could stay in this thread, as we seem to be still talking about filtering on "Erledigt"--both for the Form and the Report.

Mods, please advise if we should start a new thread.

First, concerning the code, if Erledigt is a Yes/No field, then this will not work:

Expand|Select|Wrap|Line Numbers
  1. Me.Filter = "Erledigt = " & _
  2.     IIf(fFilter, "False or True", "False")
It should more properly be:

Expand|Select|Wrap|Line Numbers
  1. Me.Filter = IIf(fFilter, "Erledigt = True Or Erledigt = False", _
  2.     "Erledigt = False")
This will properly set the filter to your desired results.

Concerning the report, keep in mind that you must also filter your Report according to the same criteria as your Form. Even though the Form is based on a Table and you have filtered the data in the Table for the Form, all the data in the Table still exists, so when the report gathers its data, it is looking at all the data. One way of opening the report this way is to perform a similar function when you call the Report:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "ReportName", acViewPreview, , _
  2.     IIf(fFilter, "Erledigt = True Or Erledigt = False", _
  3.         "Erledigt = False")
I'm not sure if this is bringing you closer to solution, as I am still just a bit unsure of your question, as your final statement
I would preferably be able to look up a customer (that has several Service contracts) and ONLY print those out.
seems to imply a bit more....
Mar 2 '15 #11
iskov
7
This does not solve my Problem is at will still only Show ALL of the "erledigt" or ALL of the "non-erledigt"

I have at the Moment in my database two different customers:

Danish Crown Konzern

And

Tönnies Konzern

in a form I Show Information such as CustomerName, Subsidiary, data etcetc, in my searchfield (txtsearch) that is connected with the button:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Befehl104_Click()
  2. Dim strsearch As String
  3. Dim strText As String
  4. Dim filterstr As String
  5.  
  6. If (Len(Txtsearch.Value) > 0) Then
  7.     strText = Me.Txtsearch.Value
  8.     strsearch = "SELECT * from ServiceAuftragTabelleQ where ((Unternehmen like ""*" & strText & "*"") or (NiederlassungName like ""*" & strText & "*"") or (AuftragAxapta like ""*" & strText & "*"") or (AuftragKunde like ""*" & strText & "*"") or (Typ like ""*" & strText & "*"") or (Art like ""*" & strText & "*"") or (DatumAngelegt like ""*" & strText & "*"") or (DatumEinsatzGeplant like ""*" & strText & "*"") or (AnsprechspartnerKunde like ""*" & strText & "*"") or (AnsprechspartnerITEC like ""*" & strText & "*"") or (ServicemitarbeiterITEC like ""*" & strText & "*""))"
  9.     Me.RecordSource = strsearch
  10. Else
  11.     strsearch = "SELECT * from ServiceAuftragTabelleQ"
  12.     Me.RecordSource = strsearch
  13. End If
  14.  
  15. Me.Filter = "Erledigt = " & _
  16.    IIf(fFilter, "False or True", "False")
  17. Me.FilterOn = True
  18. End Sub
this allows me two fx only Show the customer-contracts from Tönnies, when I wanna Report just those, the Report will still Show ALL of them.

EDIT: Unternehmen is CustomerName and Niederlassung is Subsidiary (think that would be the best Translation)
Mar 2 '15 #12
twinnyfo
3,653 Expert Mod 2GB
Still sticking with this thread for now.....

First let me suggest a minor tweak to somewhat shorten and clean up the code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Befehl104_Click()
  2.     Dim strSearch As String
  3.     Dim strText As String
  4.     Dim filterstr As String
  5.  
  6.     If (Len(txtSearch.Value) > 0) Then
  7.         strText = " Like '*" & Me.txtSearch.Value & "*'"
  8.         strSearch = "SELECT * FROM ServiceAuftragTabelleQ " & _
  9.             "WHERE ((Unternehmen" & strText & _
  10.                 ") OR (NiederlassungName" & strText & _
  11.                 ") OR (AuftragAxapta" & strText & _
  12.                 ") OR (AuftragKunde" & strText & _
  13.                 ") OR (Typ" & strText & _
  14.                 ") OR (Art" & strText & _
  15.                 ") OR (DatumAngelegt" & strText & _
  16.                 ") OR (DatumEinsatzGeplant" & strText & _
  17.                 ") OR (AnsprechspartnerKunde" & strText & _
  18.                 ") OR (AnsprechspartnerITEC" & strText & _
  19.                 ") OR (ServicemitarbeiterITEC" & strText & "))"
  20.         strSearch = strSearch & _
  21.             IIf(fFilter, "", " AND Erledigt = False")
  22.         Me.RecordSource = strSearch
  23.     Else
  24.         strSearch = "SELECT * from ServiceAuftragTabelleQ"
  25.         Me.RecordSource = strSearch
  26.     End If
  27. End Sub
Note how strText includes the "Like" keyword, and the usage of single quotes. Additionally, I included the Filter string directly into the SQL Statement.

My big question is, Where is this code located? If this is on the Form, it will not affect the report at all. This is a different story altogether.

You would need to set the record source of the report to the same as that of the Form that is displayed. Or, create a standalone query that takes into account all of the search criteria.

You have several options, all of which would require some rework.

However, I would recommend, at this point, beginning a new thread with a specific question concerning filtering the report based on multiple criteria, as this topic has gone beyond filtering a table based on a Yes/No field.

Hope this hepps!
Mar 2 '15 #13

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

Similar topics

4
by: Nhmiller | last post by:
This is directly from Access' Help: "About designing a query When you open a query in Design view, or open a form, report, or datasheet and show the Advanced Filter/Sort window (Advanced...
4
by: crispywafers | last post by:
Hi, Is it possible to filter ontop of the current filter being applied to records? This seems like it should be easy? I have two drop down boxes-- one to filter on a student's last name, one...
2
by: cefrancke | last post by:
I have a form (no underlying record set) that has two separate sub-forms on it. Each sub-form has data from two different tables. Above each sub-form there is one unbound combo box with a SQL...
2
by: Dave White | last post by:
Hello everyone, When I open this Form it displays all the records I then use a command button to apply a filter to these records. I would like to change the command buttom to a toggle switch...
2
by: Dean Slindee | last post by:
Anybody written code in VB.NET to: 1) show a print preview window of reports already written and stored in an Access 2002 database; or 2) execute the print of a report stored in an Access 2002...
2
by: amir | last post by:
How can I filter my database in Multiple way, I mean that I wana to filter st. like this: sm* *th* *er Please Help me on this matter Amir
1
by: Jackmac | last post by:
Hi there, Hopefully an easy one for someone. I'm writing a small app (Visual Studio 2008) which will take an existing access database we have and show it in a form I'm writing. The fields have...
7
by: munkee | last post by:
Hi all, I am using Allen's excellent form filter script to filter the results from a query. I would now like to add some further functionality. How do I go about displaying say the top N costs...
2
by: Ian Anderson | last post by:
Hello there, SO i have the followign VB code in my continuous form... 'Purpose: This module illustrates how to create a search form, _ where the user can enter as many or few...
18
by: Becker | last post by:
I have a combo box with a list a values that when picked the form should filter to show the corresponding record from a table. Everything works fine when I open up the form by itself. However, I...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.