473,657 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

filters

hi all !

my client wants to bring out data into a report with a number of
filters that are chosen by the user .
eg. -Section
-Days to search
-Type of care

ive never tried this before so im not sure how to go about it.
the tricky part is that there are a number of options to choose in each
of these filters or the user can choose "ALL" in each of the the
filters which is the part im finding hard.
how do i do this in a query or number of querys ??

thanks

brino

Dec 4 '06 #1
2 1640
On 4 Dec 2006 03:15:33 -0800, "brino" <bd************ *@yahoo.com.au>
wrote:

Filtering is applying a WHERE clause, which is one of the arguments of
DoCmd.OpenRepor t. Your job is to inspect the selections on the form,
and concatenate the right one.
You might pass in:
"Section=1 and DaysToSearch between #12/1/2006# and #12/31/2006#"
or if All sections have been chosen, that part of the WHERE clause
does not apply (does not need to restrict):
"DaysToSear ch between #12/1/2006# and #12/31/2006#"

-Tom.
>hi all !

my client wants to bring out data into a report with a number of
filters that are chosen by the user .
eg. -Section
-Days to search
-Type of care

ive never tried this before so im not sure how to go about it.
the tricky part is that there are a number of options to choose in each
of these filters or the user can choose "ALL" in each of the the
filters which is the part im finding hard.
how do i do this in a query or number of querys ??

thanks

brino
Dec 4 '06 #2
As TVS said, the easiest way is to build up a filter by checking each
of the filter selectors and appending a 'where' condition to the
Form.Filter property. I generally use combo boxes to allow the user to
select a value from each of the fields (or a pair of combo boxes that
allows one to select from a 'Field List' on a query and then set the
value to seek}. I UNION my combobox row source with the literal "{All}"
- the curly brackets sort the 'all' value to the top of the combobox
list:

<sample combobox 'Table/Query' rowsource>

SELECT aFaculty.faClas s FROM aFaculty WHERE (((aFaculty.faC lass) Is Not
Null)) GROUP BY aFaculty.faClas s ORDER BY aFaculty.faClas s UNION SELECT
"{All}" FROM uSysCtl;

</sample combobox 'Table/Query' rowsource>

Note that uSysCtl is my generic system control values table. It can
have only one row, so the dummy 'SELECT' statement actually only
returns the literal '{All}'. This combobox looks at the recordset I'm
setting the filter on and returns a list of all distinct values of
aFaculty("Class ").

Them add an Event to each of the filter controls 'OnChange'. In this
sample application, all of the filter controls _OnChange events
reference a common subroutine SetFilter().

<Combobox OnChange Event>

Private Sub txtFilterClass_ Change()
SetFilter
End Sub

</Combobox OnChange Event>

and finally the SetFilter subroutine:

<SQL filtering example>
Private Sub SetFilter()
On Error GoTo SetFilterErr

Dim wkFilter As String

wkFilter = ""
Select Case Me.txtFilterFTP T
Case "{All}": wkFilter = ""
Case "FT": wkFilter = "([faStatus] = ""FT"") AND "
Case "PT": wkFilter = "([faStatus] <""FT"") AND "
End Select

If (Me.txtFilterTe rm <"{All}") Then wkFilter = wkFilter &
"([faTerm] = """ & Me.txtFilterTer m & """) AND "
If (Me.txtFilterSt atus <"{All}") Then wkFilter = wkFilter &
"([faStatus] = """ & Me.txtFilterSta tus & """) AND "
If (Me.txtFilterCl ass <"{All}") Then wkFilter = wkFilter &
"([faClass] = """ & Me.txtFilterCla ss & """) AND "
If (Me.txtFilterDi vision <"{All}") Then wkFilter = wkFilter &
"([faDivision] = """ & Me.txtFilterDiv ision & """) AND "
If (Me.txtFilterDe pt <"{All}") Then wkFilter = wkFilter &
"([faDept] = """ & Me.txtFilterDep t & """) AND "
If (Len(Me.txtSear chFor) 0) Then
If ((InStr(Me.txtS earchFor, "*") 0) Or (InStr(Me.txtSe archFor,
"?") 0)) Then
wkFilter = wkFilter & "([" & Me.txtSearch & "] LIKE """ &
Me.txtSearchFor & """) AND "
Else
wkFilter = wkFilter & "([" & Me.txtSearch & "] = """ &
Me.txtSearchFor & """) AND "
End If
End If

If (Me.chkViewSele cted = True) Then wkFilter = wkFilter & "([faOK] =
True) AND "

If (Len(wkFilter) = 0) Then
Me.Filter = ""
Me.FilterOn = False
Else
Me.Filter = Left(wkFilter, Len(wkFilter) - 5)
Me.FilterOn = True
End If

Forms.frmMain.P rog 0, DCount("[faEmplID]", "aFaculty", "[faOK] =
True") & " faculty members selected."

SetFilterExit:
Exit Sub

SetFilterErr:
Select Case Err
Case 438:
Resume Next
Case Else
Resume SetFilterExit
End Select
End Sub
</SQL filtering example>

So this example appends a substring for any active filters together to
create the final SQL 'Where' clause that the .Filter property is set
to.

Finally, this routine updates each filtering combobox in case any new
values have been entered and clears any filters that have been set:

<Clear filtering comboboxes>

Private Sub ResetFilter()
Me.txtFilterFTP T.Requery
Me.txtFilterSta tus.Requery
Me.txtFilterCla ss.Requery
Me.txtFilterDiv ision.Requery
Me.txtFilterDep t.Requery
Me.txtFilterTer m.Requery
Me.chkViewSelec ted = False

Me.txtFilterFTP T = "{All}"
Me.txtFilterSta tus = "{All}"
Me.txtFilterCla ss = "{All}"
Me.txtFilterDiv ision = "{All}"
Me.txtFilterDep t = "{All}"
Me.txtFilterTer m = "{All}"

Me.txtSearch = ""
Me.txtSearchFor = ""
SetFilter
End Sub

</Clear filtering comboboxes>

Hopefully all this is clear. If anything is not let me know. Google
Groups autom,atically text wraps so some of the VBA will throw an error
if you just copy and paste. You'll have to getr rid of the extra line
feeds that are inserted.
Ron, King of Chi

Dec 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1819
by: shumaker | last post by:
I'm trying to defeat persistant filters with the following code in Close, and also in Unload: Private Sub Form_Close() DoCmd.RunCommand acCmdRemoveFilterSort Me.FilterOn = False Me.OrderByOn = False Me.ServerFilterByForm = False My.OrderBy = "" Me.Filter = ""
4
11299
by: Aaron | last post by:
Hello all. I am trying to avoid my users from saving filters. The fact is that after they use or change a filter, when closing the form Access would ask: "Do you want to save changes to the design of form?" and save the new filter. I've tried using Me.Filter = "" in the unload event, but Access asks and saves BEFORE getting to the unload, and it saves the filter before I clear it.
69
6378
by: DeJuan Jackson | last post by:
Just dropping a quick not for Tom Lane. I sent a personal message today, but I wasn't sure if you'd get it after I remembered all of the spam filters you've got set up. Sorry for the off topic post. ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html
6
6348
by: TJO | last post by:
Below is some sample code that fades div tags that is not working in IE 6.0.29 on xp sp2. Can anyone help see why the if(ie5) document.getElementById(divID).filters.alpha.opacity lines are not working ? I cannot find a solution yet. THanks <script type="text/javascript" language=javascript> var ie5 = (document.all && document.getElementById); var ns6 = (!document.all && document.getElementById);
1
1765
by: Dieter Vanderelst | last post by:
Hello, I'm trying to access the Filters-Dll provided by the filters-project (http://filters.sourceforge.net/index.htm). Following the advice I got from the Python list -thank you for that-, I do this using ctypes (http://starship.python.net/crew/theller/ctypes/index.html). I can seem to access the image filters now provided by the Dll. But
5
2526
by: dananrg | last post by:
I would like to learn how to roll my own filter ala early 90's filters like Jive, Fudd, Kraut, Moron, etc, that take text as an input, and re-writes the text adding general hilarity of various linguistic flavor (depending on the filter). I always loved running my philosophy papers, or anything that sounded "too dang serious" through filters. Gave me a new perspective on my own writing. Running the screenplay of the Empire Strikes Back...
6
6249
by: smcdonald | last post by:
I have a report that opens up using a pretty complex query. I then pop up a form with combo boxes so the user can apply a filter to the existing report and then refresh the report. I need to export the report's records with the applied query to excel in datasheet form and it needs to contain the additional filters that the user selects. The reports datasource is the original query. Right now I have this and get the datasheet format, but I...
0
1693
by: kucol | last post by:
Hi guys, I wanted to ask you for help as I am struggling with it second evening already... I have got tables DEVICES and PARTS. One device can consist of multiple parts. But... I have also another table - FILTERS (id int, type int, is_not int,
5
2791
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 results of the users filters or print everything if there is no filters submitted within the form. Any suggestions
0
2321
by: CatchSandeepVaid | last post by:
We all know that one-to-one associations are non-lazly fetched but during this fetching the filters are not applied. I debugged hibernate code and found that hibernate finally calls EntityLoader.loadByUniqueKey() method: public Object loadByUniqueKey(SessionImplementor session, Object key) throws HibernateException { return load(session, key, null, null); } I can understand that why filters are not applied because all one-to-one...
0
8411
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8838
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7351
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.