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
Try something like this in the module for your form: - Option Compare Database
-
Option Explicit
-
-
Private fFilter As Boolean
-
-
Private Sub cmdFilter_Click()
-
Me.Filter = "Erledigt = " & _
-
IIf(fFilter, "True", "False")
-
Me.FilterOn = True
-
fFilter = not fFilter
-
End Sub
Tschüss!
12 4080
Try something like this in the module for your form: - Option Compare Database
-
Option Explicit
-
-
Private fFilter As Boolean
-
-
Private Sub cmdFilter_Click()
-
Me.Filter = "Erledigt = " & _
-
IIf(fFilter, "True", "False")
-
Me.FilterOn = True
-
fFilter = not fFilter
-
End Sub
Tschüss!
Vielen Dank, dass war sehr erfolgreich!!!!
;-)
@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
I would recommend changing the Caption on the Command Button: - Me.cmdFilter.Caption = IIf(fFilter, "Un-Filter", "Filter")
between lines 6 and 7....
Thank you once again, I like the idea alot!
Glad I could be of assistance!
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: - Private Sub Befehl104_Click()
-
Dim strsearch As String
-
Dim strText As String
-
Dim filterstr As String
-
-
If (Len(Txtsearch.Value) > 0) Then
-
strText = Me.Txtsearch.Value
-
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 & "*""))"
-
Me.RecordSource = strsearch
-
Else
-
strsearch = "SELECT * from ServiceAuftragTabelleQ"
-
Me.RecordSource = strsearch
-
End If
-
-
Me.Filter = "Erledigt = " & _
-
IIf(fFilter, "False or True", "False")
-
Me.FilterOn = True
-
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: -
Private Sub Befehl101_Click()
-
Me.Befehl101.Caption = IIf(fFilter, "Alle anzeigen", "Nur offene anzeigen")
-
Me.Filter = "Erledigt = " & _
-
IIf(fFilter, "False", "False or True")
-
Me.FilterOn = True
-
fFilter = Not fFilter
-
-
End Sub
-
That is the filter button, and this is what the Report button Looks like at the Moment: - Private Sub Befehl109_Click()
-
Dim strWhere As String
-
If Me.Dirty Then Me.Dirty = False
-
If Me.FilterOn Then strWhere = Me.Filter
-
DoCmd.OpenReport "ServiceAufträgeR", acViewPreview, , strWhere
-
End Sub
-
If anything is unclear, please feel free to ask!
Anders Iskov
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: - IIf(fFilter, True, False)
Notice the lack of quotes around the True and False Values. This may be setting off your filter issues.
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
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: - Me.Filter = "Erledigt = " & _
-
IIf(fFilter, "False or True", "False")
It should more properly be: - Me.Filter = IIf(fFilter, "Erledigt = True Or Erledigt = False", _
-
"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: - DoCmd.OpenReport "ReportName", acViewPreview, , _
-
IIf(fFilter, "Erledigt = True Or Erledigt = False", _
-
"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....
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: - Private Sub Befehl104_Click()
-
Dim strsearch As String
-
Dim strText As String
-
Dim filterstr As String
-
-
If (Len(Txtsearch.Value) > 0) Then
-
strText = Me.Txtsearch.Value
-
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 & "*""))"
-
Me.RecordSource = strsearch
-
Else
-
strsearch = "SELECT * from ServiceAuftragTabelleQ"
-
Me.RecordSource = strsearch
-
End If
-
-
Me.Filter = "Erledigt = " & _
-
IIf(fFilter, "False or True", "False")
-
Me.FilterOn = True
-
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)
Still sticking with this thread for now.....
First let me suggest a minor tweak to somewhat shorten and clean up the code: - Private Sub Befehl104_Click()
-
Dim strSearch As String
-
Dim strText As String
-
Dim filterstr As String
-
-
If (Len(txtSearch.Value) > 0) Then
-
strText = " Like '*" & Me.txtSearch.Value & "*'"
-
strSearch = "SELECT * FROM ServiceAuftragTabelleQ " & _
-
"WHERE ((Unternehmen" & strText & _
-
") OR (NiederlassungName" & strText & _
-
") OR (AuftragAxapta" & strText & _
-
") OR (AuftragKunde" & strText & _
-
") OR (Typ" & strText & _
-
") OR (Art" & strText & _
-
") OR (DatumAngelegt" & strText & _
-
") OR (DatumEinsatzGeplant" & strText & _
-
") OR (AnsprechspartnerKunde" & strText & _
-
") OR (AnsprechspartnerITEC" & strText & _
-
") OR (ServicemitarbeiterITEC" & strText & "))"
-
strSearch = strSearch & _
-
IIf(fFilter, "", " AND Erledigt = False")
-
Me.RecordSource = strSearch
-
Else
-
strSearch = "SELECT * from ServiceAuftragTabelleQ"
-
Me.RecordSource = strSearch
-
End If
-
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!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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: 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: 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,...
|
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: 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...
| |