473,612 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MS Access Form Filter

4 New Member
Hi,

I've developed a form filter that produces a number of hours budgeted by employee/location/practice group/experience level and date available using some Allen Browne code. I have two command buttons, cmdFilter and cmdFilterAvail. cmdFilter filters the form based on the criteria selected via my list and text box filters. One of the fields in the form, text51 has a control source:=IIf([clientname]="Unassigned Time",[BudgetedHours],Null)

On click, cmdFilter filters my results but also shows the null values present in the data set where clientname <> "Unassigned Time". I'd like cmdFilterAvail to be able to keep the filters applied, but then narrow my data set to NON-NULL text51 values thereby showing only employees with available time.

Code for frmFilterAvail is identical to frmFilter and needs to have the NON-NULL piece added and I don't know how to do it...Help would be greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdfilteravail_Click()
  2.   'Purpose:   Build up the criteria string from the non-blank search boxes, and apply to the form's Filter.
  3.     'Notes:     1. We tack " AND " on the end of each condition so you can easily add more search boxes; _
  4.                         we remove the trailing " AND " at the end.
  5.     '           2. The date range works like this: _
  6.                         Both dates      = only dates between (both inclusive. _
  7.                         Start date only = all dates from this one onwards; _
  8.                         End date only   = all dates up to (and including this one).
  9.     Dim strWhere As String                  'The criteria string.
  10.     Dim strExperienceLevel As String
  11.     Dim strPracticeGroup As String
  12.     Dim strLocation As String
  13.     Dim varSelected As Variant
  14.     Dim lngLen As Long                      'Length of the criteria string to append to.
  15.     Const conJetDate = "\#mm\/dd\/yyyy\#"   'The format expected for dates in a JET query string.
  16.  
  17.     '***********************************************************************
  18.     'Look at each search box, and build up the criteria string from the non-blank ones.
  19.     '***********************************************************************
  20.     'Text field example. Use quotes around the value in the string.
  21.     If Me.txtFilterExperienceLevel.ItemsSelected.Count > 0 Then
  22.     For Each varSelected In Me.txtFilterExperienceLevel.ItemsSelected
  23.     strExperienceLevel = strExperienceLevel & ",""" & Me.txtFilterExperienceLevel.ItemData(varSelected) & Me.txtFilterExperienceLevel & """"
  24.     Next varSelected
  25.     strExperienceLevel = Mid(strExperienceLevel, 2)  'REMOVES LEADING COMMA
  26.     strWhere = strWhere & "([ExperienceLevel] IN (" & strExperienceLevel & ")) AND "
  27.     End If
  28.  
  29.     If Not IsNull(Me.txtFilterExperienceLevel) Then
  30.         strWhere = strWhere & "([ExperienceLevel] = """ & Me.txtFilterExperienceLevel & """) AND "
  31.     End If
  32.  
  33.     If Me.txtFilterPracticeGroup.ItemsSelected.Count > 0 Then
  34.     For Each varSelected In Me.txtFilterPracticeGroup.ItemsSelected
  35.     strPracticeGroup = strPracticeGroup & ",""" & Me.txtFilterPracticeGroup.ItemData(varSelected) & Me.txtFilterPracticeGroup & """"
  36.     Next varSelected
  37.     strPracticeGroup = Mid(strPracticeGroup, 2)  'Removes leading comma
  38.     strWhere = strWhere & "([PracticeGroup] IN (" & strPracticeGroup & ")) AND "
  39.     End If
  40.  
  41.     If Not IsNull(Me.txtFilterPracticeGroup) Then
  42.         strWhere = strWhere & "([PracticeGroup] = """ & Me.txtFilterPracticeGroup & """) AND "
  43.     End If
  44.  
  45.     If Me.txtfilterlocation.ItemsSelected.Count > 0 Then
  46.     For Each varSelected In Me.txtfilterlocation.ItemsSelected
  47.     strLocation = strLocation & ",""" & Me.txtfilterlocation.ItemData(varSelected) & Me.txtfilterlocation & """"
  48.     Next varSelected
  49.     strLocation = Mid(strLocation, 2)  'Removes leading comma
  50.     strWhere = strWhere & "([Location] IN (" & strLocation & ")) AND "
  51.     End If
  52.  
  53.     If Not IsNull(Me.txtfilterlocation) Then
  54.         strWhere = strWhere & "([Location] = """ & Me.txtfilterlocation & """) AND "
  55.     End If
  56.  
  57.     'Another text field example. Use Like to find anywhere in the field.
  58.     If Not IsNull(Me.txtFilterMainName) Then
  59.         strWhere = strWhere & "([EmployeeName] Like ""*" & Me.txtFilterMainName & "*"") AND "
  60.     End If
  61.  
  62.     'Date field example. Use the format string to add the # delimiters and get the right international format.
  63.     If Not IsNull(Me.txtStartDate) Then
  64.         strWhere = strWhere & "([BudgetDate] >= " & Format(Me.txtStartDate, conJetDate) & ") AND "
  65.     End If
  66.  
  67.     'Another date field example. Use "less than the next day" since this field has times as well as dates.
  68.     If Not IsNull(Me.txtEndDate) Then   'Less than the next day.
  69.         strWhere = strWhere & "([BudgetDate] < " & Format(Me.txtEndDate + 1, conJetDate) & ") AND "
  70.     End If
  71.  
  72.     '***********************************************************************
  73.     'Chop off the trailing " AND ", and use the string as the form's Filter.
  74.     '***********************************************************************
  75.     'See if the string has more than 5 characters (a trailing " AND ") to remove.
  76.     lngLen = Len(strWhere) - 5
  77.     If lngLen <= 0 Then     'Nah: there was nothing in the string.
  78.         MsgBox "No criteria", vbInformation, "Nothing to do."
  79.     Else                    'Yep: there is something there, so remove the " AND " at the end.
  80.         strWhere = Left$(strWhere, lngLen)
  81.         'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
  82.         'Debug.Print strWhere
  83.  
  84.        'Finally, apply the string as the form's Filter.
  85.         Me.Filter = strWhere
  86.         Me.FilterOn = True
  87.     End If
  88. End Sub
Sep 8 '10 #1
0 1416

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

Similar topics

0
2066
by: Mike O. | last post by:
MS Access 2003 "filter by form" has drop down lists that allow the user to select values for each field to filter by. However, once some values are selected,the remaining dropdown lists remain the same and aren't progressively filtered to reflect the selections already made in other fields. This can be very tedious when filtering a large datasheet. Unlike Access, the MS Excel autofilter has automatic progressive filtering of value...
14
2359
by: Nothing | last post by:
I have a form that has a Tab Control on it. On one of the tab control pages, there are only 3 pages, is a combo box based on a field called departments in a table. When the user selects one of the departments from the combo box I want a sub-form to open on the tab control page based on the department selected. The sub-form is based on a query that pulls all employee data, so if a user selects admissions, I want the subform to open and...
4
6605
by: wecka | last post by:
Hello All, Does any one know how to use the form filter in Access to provide partial match? When you choose to "form filter," all text boxes will convert to combo boxes where you can choose from the already stored data in the corresponding tables. But for example I want to match all records containing the word John (assume it is a name field). If there is a way to do this, it will save my life from having to write a big chunck of SQL code...
2
5914
by: Henrootje | last post by:
Hello there! I have a piece of code in a module (function) that constructs a filter. But now I run into a problem..... It seems that I can only set a filter form a module if I open the form in design mode.............. (that is, if changing the filter from a module / called function) But that means any other changes I made on the form (such as f..e. the
5
5539
by: phill86 | last post by:
Hi, I have a form that I have applied a filter to by using combo boxes which works fine. Is there a way to apply that filter to the forms underlying query Here is the code that I use to filter the form On Error GoTo Error_EquipFilter
2
3596
by: phill86 | last post by:
Hi, I am filtering a report using the form filter with the following code DoCmd.OpenReport "report1", acViewReport, , Me.filter Which works fine untill I filter the form on one of the fields which is a lookup field and I get the enter parameter value box which is looking for the Assetdetails.details field which contains the following text for some reason it has put Lookup_ at the front of the field
1
4073
by: whkoh | last post by:
I have two tables: Customer and Project with primary keys Customer ID and Project ID respectively. A third table (Involvement) is the intersection table storing Customer ID and Project ID as foreign keys. I need to select Project.* given Customer.. So far my query is SELECT Project.* FROM Project INNER JOIN (Customer INNER JOIN Involvement ON (Customer. = Involvement.) AND (Customer. = Involvement.)) ON (Project. = Involvement.) AND...
1
1552
by: Obenash | last post by:
Is it possible to filter a data entry form with multiple subforms. I have a form that is used to enter data into the database and the form has multiple subforms and I wanted to filter it to make it easier to move from one subform to another. If it is possible, I will need help on how to do that. Thanks in advance. Obenash
3
1493
by: jsneed | last post by:
I have a database that is going pretty good. The only problem I have been having is using a form to filter a table by description. In the table I have Part Number, description, vendor, utilized on, min, max, and ex. I want to be able to have my form filter the table by using the description, but I don't want the user to have to type in the complete description. If they are looking for a part number and happen to know it is some kind of 2" pipe,...
7
5277
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 where in my search form I would have a drop down to select the N value and use radio buttons to select the field the top N should be run against (e.g. cost). Thanks for any help in advance my code is as follows: Option Compare Database
0
8162
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
8565
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
8246
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
8415
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7039
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...
0
4109
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2550
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
1
1695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1413
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.