473,472 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Date in criteria not processing all date records

I have a table with four date fields, some of which may not be filled
in based on our data entry needs. I have a criteria set as <date()-180
which is supposed to pull dates older than 180 days ago. The problem
is that when I use that criteria for all four fields I am not getting
the expected results.

I am trying to find out from this query is the date in date field one
is older than 180, same thing for the other three date fields. For
some reason it is not picking up all the older than 180 records. It
seems to be working fine for the first date field, after that it is
dropping relevant records.

Can someone please explain how to get the criteria in the query to
produce the results that I am looking for.

Thanks
Jun 27 '08 #1
8 2757
Dr Al wrote:
I have a table with four date fields, some of which may not be filled
in based on our data entry needs. I have a criteria set as <date()-180
which is supposed to pull dates older than 180 days ago. The problem
is that when I use that criteria for all four fields I am not getting
the expected results.

I am trying to find out from this query is the date in date field one
is older than 180, same thing for the other three date fields. For
some reason it is not picking up all the older than 180 records. It
seems to be working fine for the first date field, after that it is
dropping relevant records.

Can someone please explain how to get the criteria in the query to
produce the results that I am looking for.

Thanks
If you have the criteria under all the fields on the same row in the query
designer then you will only get rows where ALL of the dates are older than
180 days. Is that what you want?

If you want all rows where ANY of the dates is older than 180 days then the
criteria need to be on separate rows.

Same row = AND
Separate rows = OR

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Jun 27 '08 #2

"Rick Brandt" <ri*********@hotmail.comwrote in message
news:dy*****************@newssvr19.news.prodigy.ne t...
Dr Al wrote:
I have a table with four date fields, some of which may not be filled
in based on our data entry needs. I have a criteria set as <date()-180
which is supposed to pull dates older than 180 days ago. The problem
is that when I use that criteria for all four fields I am not getting
the expected results.

I am trying to find out from this query is the date in date field one
is older than 180, same thing for the other three date fields. For
some reason it is not picking up all the older than 180 records. It
seems to be working fine for the first date field, after that it is
dropping relevant records.

Can someone please explain how to get the criteria in the query to
produce the results that I am looking for.

Thanks

If you have the criteria under all the fields on the same row in the query
designer then you will only get rows where ALL of the dates are older than
180 days. Is that what you want?

If you want all rows where ANY of the dates is older than 180 days then
the
criteria need to be on separate rows.

Same row = AND
Separate rows = OR

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com

Adding to Rick's post, replacing <date()-180 with <dateadd("d",-180,date())
may prevent some future problems.
Jun 27 '08 #3
On Apr 17, 5:00*pm, "paii, Ron" <n...@no.comwrote:
"Rick Brandt" <rickbran...@hotmail.comwrote in message

news:dy*****************@newssvr19.news.prodigy.ne t...
Dr Al wrote:
I have a table with fourdatefields, some of which may not be filled
in based on our data entry needs. I have acriteriaset as <date()-180
which is supposed to pull dates older than 180 days ago. The problem
is that when I use thatcriteriafor all four fields I am not getting
the expected results.
I am trying to find out from this query is thedateindatefield one
is older than 180, same thing for the other threedatefields. For
some reason it is not picking up all the older than 180 records. It
seems to be working fine for the firstdatefield, after that it is
dropping relevant records.
Can someone please explain how to get thecriteriain the query to
produce the results that I am looking for.
Thanks
If you have thecriteriaunder all the fields on the same row in the query
designer then you will only get rows where ALL of the dates are older than
180 days. *Is that what you want?
If you want all rows where ANY of the dates is older than 180 days then
the
criterianeed to be on separate rows.
Same row = AND
Separate rows = OR
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt * at * Hunter * dot * com

Adding to Rick's post, replacing <date()-180 with <dateadd("d",-180,date())
may prevent some future problems.- Hide quoted text -

- Show quoted text -
I tried <date()180 on a seperate row for each date record, but it is
dropping records that may only have one or two date records populated.
At that point records in the third and fourth date field are picking
up fields with dates that are less than 180. I did try the
<dateadd("d",-180,date()), on a seperate line but that is giving the
same results, it is dropping fields that may be null and picking up
fields in date 3 or date 4 that are less than 180.

I am trying to find out which records based on date fields 1 through 4
are greater than 180 days.

Thanks
Jun 27 '08 #4
On Thu, 17 Apr 2008 19:51:21 -0700 (PDT), Dr Al <gr*********@hotmail.com>
wrote:
>On Apr 17, 5:00*pm, "paii, Ron" <n...@no.comwrote:
>"Rick Brandt" <rickbran...@hotmail.comwrote in message

news:dy*****************@newssvr19.news.prodigy.n et...
Dr Al wrote:
I have a table with fourdatefields, some of which may not be filled
in based on our data entry needs. I have acriteriaset as <date()-180
which is supposed to pull dates older than 180 days ago. The problem
is that when I use thatcriteriafor all four fields I am not getting
the expected results.
I am trying to find out from this query is thedateindatefield one
is older than 180, same thing for the other threedatefields. For
some reason it is not picking up all the older than 180 records. It
seems to be working fine for the firstdatefield, after that it is
dropping relevant records.
Can someone please explain how to get thecriteriain the query to
produce the results that I am looking for.
Thanks
If you have thecriteriaunder all the fields on the same row in the query
designer then you will only get rows where ALL of the dates are older than
180 days. *Is that what you want?
If you want all rows where ANY of the dates is older than 180 days then
the
>criterianeed to be on separate rows.
Same row = AND
Separate rows = OR
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt * at * Hunter * dot * com

Adding to Rick's post, replacing <date()-180 with <dateadd("d",-180,date())
may prevent some future problems.- Hide quoted text -

- Show quoted text -

I tried <date()180 on a seperate row for each date record, but it is
dropping records that may only have one or two date records populated.
At that point records in the third and fourth date field are picking
up fields with dates that are less than 180. I did try the
<dateadd("d",-180,date()), on a seperate line but that is giving the
same results, it is dropping fields that may be null and picking up
fields in date 3 or date 4 that are less than 180.

I am trying to find out which records based on date fields 1 through 4
are greater than 180 days.

Thanks
Check all the dates in all the date fields in the table(s). Make sure that the
person entering the dates can not enter dd/mm/yyyy or mm/dd/yy if your program
is expecting to see mm/dd/yyyy. Data entry is critical. Garbage in garbage
out.

Chuck
Jun 27 '08 #5

"Dr Al" <gr*********@hotmail.comwrote in message
news:39**********************************@m71g2000 hse.googlegroups.com...
On Apr 17, 5:00 pm, "paii, Ron" <n...@no.comwrote:
"Rick Brandt" <rickbran...@hotmail.comwrote in message

news:dy*****************@newssvr19.news.prodigy.ne t...
Dr Al wrote:
I have a table with fourdatefields, some of which may not be filled
in based on our data entry needs. I have acriteriaset as <date()-180
which is supposed to pull dates older than 180 days ago. The problem
is that when I use thatcriteriafor all four fields I am not getting
the expected results.
I am trying to find out from this query is thedateindatefield one
is older than 180, same thing for the other threedatefields. For
some reason it is not picking up all the older than 180 records. It
seems to be working fine for the firstdatefield, after that it is
dropping relevant records.
Can someone please explain how to get thecriteriain the query to
produce the results that I am looking for.
Thanks
If you have thecriteriaunder all the fields on the same row in the query
designer then you will only get rows where ALL of the dates are older
than
180 days. Is that what you want?
If you want all rows where ANY of the dates is older than 180 days then
the
criterianeed to be on separate rows.
Same row = AND
Separate rows = OR
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com

Adding to Rick's post, replacing <date()-180 with
<dateadd("d",-180,date())
may prevent some future problems.- Hide quoted text -

- Show quoted text -
I tried <date()180 on a seperate row for each date record, but it is
dropping records that may only have one or two date records populated.
At that point records in the third and fourth date field are picking
up fields with dates that are less than 180. I did try the
<dateadd("d",-180,date()), on a seperate line but that is giving the
same results, it is dropping fields that may be null and picking up
fields in date 3 or date 4 that are less than 180.

I am trying to find out which records based on date fields 1 through 4
are greater than 180 days.

Thanks

You need to account for the NULL values. The query's WHERE clause may need
to be like the following, using your table and field names. Assuming your
date fields are Date/Time fields and not string.

WHERE (((tablename.Date1) Is Not Null And
(tablename.Date1)<DateAdd("d",-180,Date()))) OR (((tablename.Date2) Is Not
Null And (tablename.Date2)<DateAdd("d",-180,Date()))) OR (((tablename.Date3)
Is Not Null And (tablename.Date3)<DateAdd("d",-180,Date()))) OR
(((tablename.Date4) Is Not Null And
(tablename.Date4)<DateAdd("d",-180,Date())));
Jun 27 '08 #6
paii, Ron wrote:
I tried <date()180 on a seperate row for each date record, but it is
dropping records that may only have one or two date records populated.
At that point records in the third and fourth date field are picking
up fields with dates that are less than 180. I did try the
<dateadd("d",-180,date()), on a seperate line but that is giving the
same results, it is dropping fields that may be null and picking up
fields in date 3 or date 4 that are less than 180.

I am trying to find out which records based on date fields 1 through 4
are greater than 180 days.
Please clarify this last statement as it makes no sense to me. Perhaps if
you also posted a few examples of records you want the query to return along
with a few that the query should not return.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Jun 27 '08 #7
On Apr 18, 7:38*pm, "Rick Brandt" <rickbran...@hotmail.comwrote:
paii, Ron wrote:
I tried <date()180 on a seperate row for each date record, but it is
dropping records that may only have one or two date records populated.
At that point records in the third and fourth date field are picking
up fields with dates that are less than 180. I did try the
<dateadd("d",-180,date()), on a seperate line but that is giving the
same results, it is dropping fields that may be null and picking up
fields in date 3 or date 4 that are less than 180.
I am trying to find out which records based on date fields 1 through 4
are greater than 180 days.

Please clarify this last statement as it makes no sense to me. *Perhaps if
you also posted a few examples of records you want the query to return along
with a few that the query should not return.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt * at * Hunter * dot * com

Here is what the sql code looks like for the 14 day query:

SELECT [Primary Table].ID, [Primary Table].[Last Name], [Primary
Table].[Date of 1st Letter], [Primary Table].[Date of 2nd Letter],
[Primary Table].[Date of 3rd Letter], [Primary Table].[Date of 4th
Letter]
FROM [Primary Table]
WHERE ((([Primary Table].[Date of 1st
Letter])<DateAdd("d",-14,Date()))) OR ((([Primary Table].[Date of 2nd
Letter])<DateAdd("d",-14,Date()))) OR ((([Primary Table].[Date of 3rd
Letter])<DateAdd("d",-14,Date()))) OR ((([Primary Table].[Date of 4th
Letter])<DateAdd("d",-14,Date())));

Here are the results of the query based upon the above. I did not
expect record "Tosky" to show up because it is clearly not valid for
the 14 day argument, same thing with record "Martin". I have the
criteria on a seperate row under each date field.

ID Last Name Date of 1st Letter Date of 2nd Letter Date of 3rd
Letter Date of 4th Letter
2 East 1/1/2006 1/1/2007 1/1/2008
3 Martin 3/1/2008 3/15/2008
3/30/2008 4/15/2008
4 Wilson 10/1/2007 10/16/2007 11/1/2007
11/16/2007
5 Rolek 12/1/2007 1/1/2008 2/1/2008
11 Tosky 3/1/2008 3/16/2008 4/16/2008
9 Foster 3/9/2008

Thanks.
Jun 27 '08 #8
Dr Al wrote:
Here is what the sql code looks like for the 14 day query:

SELECT [Primary Table].ID, [Primary Table].[Last Name], [Primary
Table].[Date of 1st Letter], [Primary Table].[Date of 2nd Letter],
[Primary Table].[Date of 3rd Letter], [Primary Table].[Date of 4th
Letter]
FROM [Primary Table]
WHERE ((([Primary Table].[Date of 1st
Letter])<DateAdd("d",-14,Date()))) OR ((([Primary Table].[Date of 2nd
Letter])<DateAdd("d",-14,Date()))) OR ((([Primary Table].[Date of 3rd
Letter])<DateAdd("d",-14,Date()))) OR ((([Primary Table].[Date of 4th
Letter])<DateAdd("d",-14,Date())));

Here are the results of the query based upon the above. I did not
expect record "Tosky" to show up because it is clearly not valid for
the 14 day argument, same thing with record "Martin". I have the
criteria on a seperate row under each date field.

ID Last Name Date of 1st Letter Date of 2nd Letter Date of 3rd
Letter Date of 4th Letter
2 East 1/1/2006 1/1/2007 1/1/2008
3 Martin 3/1/2008 3/15/2008
3/30/2008 4/15/2008
4 Wilson 10/1/2007 10/16/2007 11/1/2007
11/16/2007
5 Rolek 12/1/2007 1/1/2008 2/1/2008
11 Tosky 3/1/2008 3/16/2008 4/16/2008
9 Foster 3/9/2008
Assuming you ran this query today (4/19/2008) then all of those records
satisfy your query because they all have "at least one" date that is older
than 14 days. That is what an OR criteria as you have constructed will
produce.

So...what is the result you DO want? It sounds like you want all records
having NO date newer than 14 days ago. That would be accomplished with AND
rather than OR, but then you have to account for Nulls in your fields which
complicates things because now you need to have both ORs and ANDs with
proper bracketing...

WHERE (foo1 < bar OR foo1 is Null)
AND (foo2 < bar OR foo2 is Null)
AND (foo3 < bar OR foo3 is Null)
AND (foo4 < bar OR foo4 is Null)

Frankly the difficulty in the query stems from improper design. Any time
you have repeating similar fields Date1, Date2, etc.. that is incorrect.
Your Dates should be stored as individual records in a separate table
related to this one. Then all you have to do is look at the most recent
(Max) date for each name and see which of those are more than 14 days old.

That design is also more flexible because you don't have to design in a
fixed number of "sent letter dates" you can add as many as you want because
the information only requires new *rows* of data instead of new *columns*
(the latter requiring design changes).
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com

Jun 27 '08 #9

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

Similar topics

9
by: Bob Sanderson | last post by:
I am using the following query to calculate a date for a report ... Cal Due: DateAdd("m",!,! ) I now need to select all records whose Cal Due date is less than the date of the report. I have...
3
by: Paolo | last post by:
I have a query with a field named RECEIVED in which I have the following criteria: >=DateAdd('d',-Day(Date())+1,Date()) This Criteria returns all records which show a starting with the 1st...
19
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main...
4
by: Stewart Allen | last post by:
I'm trying to filter a table that has 2 date fields, the first date will always have a value but the second will only occasionally has a value. Each date field also has a corresponding text field...
10
by: Kenneth | last post by:
I have a Query that consist of a lot of different sales data, and one of the colums are different date. The date goes from 1jan2003 til 31jan2003. in this Query I only want the salesdata for...
6
by: Megan | last post by:
Hi everybody- I'm trying to use a checkbox to control whether or not a date field in a query "Is Null" or "Is Not Null." I have 2 date fields: InDate and OutDate. If there is an OutDate, then...
3
by: Taji | last post by:
Can someone please explain this to me. When I run the following query in MS Access, it doesn't return anything. SELECT tbl_vdc.vcd_id, tbl_vdc.vcd_count, tbl_vdc.batch_day FROM tbl_vdc WHERE...
12
by: Steve Elliott | last post by:
I have a query set up to gather together data between two specified dates. Shown in the query column as: Between #24/09/2004# And #01/10/2004# Is it possible to enter several different date...
13
by: Jim Armstrong | last post by:
Hi all - This problem has been driving me crazy, and I'm hoping the answer is something stupid I am neglecting to see.... The procedure posted below is part of an Access/SQL database I have...
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...
0
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
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
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
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
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
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.