473,382 Members | 1,396 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,382 software developers and data experts.

Filter form by date

Hi
I have a form that feeds filter parameters to a report. My problem stems from using date parameters to filter.My code is as follows:

Expand|Select|Wrap|Line Numbers
  1. If IsNull(Me.Date.Value) And IsNull(Me.EndDate.Value) Then 
  2. strDate = "Like '*'"      
  3. Else          
  4. strDate = "Between " & Me.txtDate.Value & " And " & Me.txtEndDate.Value      
  5. End If
The value to be returned by the above code is supposed to any info between txtDate and txtEndDate
The date parameters are two textboxes on the form and they get values from a popup calendar.
What am I doing wrong?
Dec 12 '06 #1
7 2620
NeoPa
32,556 Expert Mod 16PB
If this is for a Filter propert then you need to specify the field that it's filtering.
Unlike in the Design Grid Criteria, the field being tested must be included.
Dec 12 '06 #2
NeoPa
32,556 Expert Mod 16PB
If no filter required then it's better to pass no filter value than one that resolves (eventually) to all records.
.Value is not required in your formulas.
Dates should be formatted correctly if passed as literals (as yours are).
Replace
Expand|Select|Wrap|Line Numbers
  1. & Me.txtDate.Value &
  2. with
  3. & Format(Me.txtDate,'\#m/d/yyyy\#') &
Dec 12 '06 #3
MMcCarthy
14,534 Expert Mod 8TB
As Adrian said you only need the filter if filter required. Something like the following.

Expand|Select|Wrap|Line Numbers
  1. Dim strCriteria As String
  2.  
  3. If Not IsNull(Me.Date) And Not IsNull(Me.EndDate) Then 
  4.    strCriteria = "[DateFieldName] Between #" & Me.txtDate & "# And #" & Me.txtEndDate & "#"
  5.    DoCmd.OpenReport "ReportName", acViewPreview, , strCriteria
  6. Else
  7.    DoCmd.OpenReport "ReportName", acViewPreview
  8. End If
  9.  
  10.  
Mary
Dec 13 '06 #4
Thanks Mary
I have realised what my mistake was. The date value from the calendar and the field on the report had different date formats plus the I did not use the (#).




As Adrian said you only need the filter if filter required. Something like the following.

Expand|Select|Wrap|Line Numbers
  1. Dim strCriteria As String
  2.  
  3. If Not IsNull(Me.Date) And Not IsNull(Me.EndDate) Then 
  4.    strCriteria = "[DateFieldName] Between #" & Me.txtDate & "# And #" & Me.txtEndDate & "#"
  5.    DoCmd.OpenReport "ReportName", acViewPreview, , strCriteria
  6. Else
  7.    DoCmd.OpenReport "ReportName", acViewPreview
  8. End If
  9.  
  10.  
Mary
Dec 13 '06 #5
MMcCarthy
14,534 Expert Mod 8TB
Thanks Mary
I have realised what my mistake was. The date value from the calendar and the field on the report had different date formats plus the I did not use the (#).
No problem. I'm glad you worked it out.

Mary
Dec 13 '06 #6
NeoPa
32,556 Expert Mod 16PB
No problem. I'm glad you worked it out.

Mary
I'm invisible! (Think scene from GoldenEye)
Dec 14 '06 #7
MMcCarthy
14,534 Expert Mod 8TB
I'm invisible! (Think scene from GoldenEye)
I'm glad you realise it. :D

Mary
Dec 14 '06 #8

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

Similar topics

0
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the...
3
by: Afton | last post by:
I would like to make a form that filters a report by Supervisor and by starting and ending date. I have the supervisors in a combo box, and that works. However, I do not know how to code to let...
1
by: lorirobn | last post by:
Hi, I have a report that works just fine. Now I would like to add the capability to choose selection criteria to limit what is displayed. I created several reports that do this, but they used...
0
by: Stinky Pete | last post by:
Hi, The db I'm trying to update has a report form from which all other statistical forms and reports are selected/printed by dept, type, cost, number etc. The report form uses a date filter to...
6
by: fonzie | last post by:
Is there any way to include two unbound text boxes (for a start date and end date) to a filter-by-form? The users may want to filter by several different fields and they may want to include a date...
5
by: Ron S | last post by:
After days of searching I finally an example that would work with my application, the only problem is after entering all of the code it is not working. Would someone be kind enough to take a look at...
2
by: jcf378 | last post by:
hi all. I have a form which contains a calculated control ("days") that outputs the # of days between two dates (DateDiff command between the fields and ). However, when I click "Filter by...
9
by: dee | last post by:
I'd like to filter by the following criteria: left(LeadDisposition,3) = "Sit" AND Appt_Date = Text767 I have no idea how to do this. Appreciate help.
1
by: Cara Murphy | last post by:
Hi There! Hoping you are able to help me with a filtering scenario: I have created a pop up form (Filter) to filter a report (Open Issues), which currently has a number of combo boxes which...
3
by: franc sutherland | last post by:
Hello, I have a report which I filter using the me.filter command in the OnOpen event. Me.Filter = "OrderID=" & Forms!variable_form_name! Me.FilterOn = True I want to be able to open that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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$) { } ...
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...

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.