473,486 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Filtering on a date in a form

7 New Member
Hi,

I want to filter the records in a form by filtering on multiple fields. The fields in the form are "ActionID", "OwnerID", "RequestorID" and "Due".
In the footer section of the form i have created following respective controls: "ActionIDFilter", "OwnerIDFilter", "RequestorIDFilter", "DueDateAfter" and "DueDateBefore".
The actual filtering gets executed after clicking the commandbutton "ApplyFiltersToToDoListForm".
Filtering runs perfect when i enter any valid value in fields "ActionIDFilter", "OwnerIDFilter" and "RequestorIDFilter".
Filtering runs not correct when i enter a valid date in fields "DueDateAfter" and "DueDateBefore".
Anyone any idea what is going wrong here ?
Thanks.
Jurgen


Expand|Select|Wrap|Line Numbers
  1. Private Sub ApplyFiltersToToDoListForm_Click()
  2.  
  3. Dim strFilter As String
  4.  
  5.     If ActionIDFilter <> "" Then
  6.         strFilter = "ActionID = " & ActionIDFilter
  7.     Else
  8.         If OwnerFilter <> "" Then
  9.             strFilter = "OwnerID = " & OwnerFilter
  10.         End If
  11.         If RequestorFilter <> "" Then
  12.             If strFilter <> "" Then
  13.                 strFilter = strFilter & " AND "
  14.             End If
  15.             strFilter = strFilter & "RequestorID = " & RequestorFilter
  16.         End If
  17.         If DueDateAfter <> "" Then
  18.             If strFilter <> "" Then
  19.                 strFilter = strFilter & " AND "
  20.             End If
  21.             strFilter = strFilter & "Due >= " & DueDateAfter
  22.         End If
  23.         If DueDateBefore <> "" Then
  24.             If strFilter <> "" Then
  25.                 strFilter = strFilter & " AND "
  26.             End If
  27.             strFilter = strFilter & "Due <= " & DueDateBefore
  28.         End If
  29.     End If
  30.  
  31.     Me.Filter = strFilter
  32.     Me.FilterOn = True
  33.  
  34. End Sub
Jan 14 '17 #1
2 1899
PhilOfWalton
1,430 Recognized Expert Top Contributor
Instead of code like DueDateAfter <> "" use
If Not IsNull(DueDateAfter)
Same applies to DueDateBefore

Dates must be surrounded with Hashes
So strFilter = strFilter & "Due <= " & DueDateBefore becomes
strFilter = strFilter & "Due <= #" & DueDateBefore & "#"
Ditto for DueDateAfter

Phil
Jan 14 '17 #2
Jurgen
7 New Member
Thank you very much, Phil !
Runs nicely !
Jan 14 '17 #3

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

Similar topics

2
4593
by: wireless | last post by:
In our database is a decimal field with format YYMMDDhhmmss.9999999999 where the 9s are random digits. I'm trying to strip off just the YYMMDD and put it in date form. So far I came up with:...
0
1601
by: Keith Shearer | last post by:
I'm having a bit of trouble, moving between controls, when filtering on a form. I'm using a continuous form. At the top I have 2 date fields. I want to filter the data specified between the two...
2
1585
by: Vic | last post by:
Dear All, I am getting the following error message : "You cannot assign a value to this object" ("Me.filter =" is highlighted) I have two comboboxes (ByGenes and BySpecies)with lists in them...
4
24423
by: Lisa Jones | last post by:
Hi Can someone tell me How do you get selected date form MonthCalendar control Thanks so muc Lisa
2
21479
by: Igor | last post by:
Can someone tell me sql query for filtering date field for current day, not last 24hours but from 00:00 to current time?
8
6385
by: Ragbrai | last post by:
Howdy All, I have a query that is used for filtering results to be used in a combo box. The query needs to test fields from both a table and then unbound text boxes on the form that also contains...
4
2174
by: roryok | last post by:
Hi, (Access 2002 & Windows XP Pro) I have a Select query and one of the columns has the following criteria: (from SQL view) HAVING (((order.orderDate)>=!! And (order.orderDate)<=!!)); This...
7
11654
by: viperRider | last post by:
This question has probably been asked, I just can't find it - sorry if I am double posting. I have a form that displays cselect info from my homebrew database (ie Name, date brewed, date bottled,...
1
1128
DAF LAD
by: DAF LAD | last post by:
Hi all, I currently have a database that has a form for input, I have created another form that looks identical to this one looking at the same data in the same tables however only one thing is...
6
1459
by: lovelydan | last post by:
I have designed a form(main form) which has a record source that runs subforms. this works perfectly. I also have a macro that is attached to this subform which filters records on a different form....
0
7099
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
7123
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,...
0
7175
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...
1
6842
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...
0
7319
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...
0
5430
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,...
1
4864
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...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1378
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 ...

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.