A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Query Criteria



 
 
Thread Tools Display Modes
  #1  
Old February 22nd, 2010, 08:59 AM posted to microsoft.public.access.queries
Faraz A. Qureshi
external usenet poster
 
Posts: 164
Default Query Criteria

I have a table "Trans" with fields [DT], [Acnt], [Amt]
I want a query to return records with dates in [DT] that are greater than or
equal to the date inserted in the [FilterForm]![FFrom] and less than or equal
to the date inserted in the [FilterForm]![FTo].

However, if [FilterForm]![FFrom] & [FilterForm]![FFrom] BOTH are NULL I want
ALL the records to be returned.

What would be the correct SQL syntax?
===
Thanx in advance & Best Regards,

Faraz!
  #2  
Old February 22nd, 2010, 02:00 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Query Criteria

IF DT ALWAYS has a value you can use the following.
WHERE Dt Between Nz(Forms![FilterForm]![FFrom],#1900-01-01#)
AND Nz(Forms![FilterForm]![FTo],#2999-12-31#)

If DT is sometimes NULL and you want the null values also when you don't input
date range then the expression becomes more complex.

WHERE (Dt =Forms![FilterForm]![FFrom] Or Forms![FilterForm]![FFrom] is Null)
AND (Dt =Forms![FilterForm]![FTo] Or Forms![FilterForm]![FTo] is Null)

Both those expressions will return records as follows
TO and From have a value : records between the dates
TO has a value, From is Null : records before the To date
To is Null, From has a value : records after the From date
Both Null : Version One all non-null records in the date range, Version 2 all
records in the table.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Faraz A. Qureshi wrote:
I have a table "Trans" with fields [DT], [Acnt], [Amt]
I want a query to return records with dates in [DT] that are greater than or
equal to the date inserted in the [FilterForm]![FFrom] and less than or equal
to the date inserted in the [FilterForm]![FTo].

However, if [FilterForm]![FFrom] & [FilterForm]![FFrom] BOTH are NULL I want
ALL the records to be returned.

What would be the correct SQL syntax?
===
Thanx in advance & Best Regards,

Faraz!

  #3  
Old February 23rd, 2010, 06:07 AM posted to microsoft.public.access.queries
Faraz A. Qureshi
external usenet poster
 
Posts: 164
Default Query Criteria

XCLent idea of using #1900-01-01# & #2999-12-31# in Nz
--
Thanx & Best Regards,

Faraz!


"John Spencer" wrote:

IF DT ALWAYS has a value you can use the following.
WHERE Dt Between Nz(Forms![FilterForm]![FFrom],#1900-01-01#)
AND Nz(Forms![FilterForm]![FTo],#2999-12-31#)

If DT is sometimes NULL and you want the null values also when you don't input
date range then the expression becomes more complex.

WHERE (Dt =Forms![FilterForm]![FFrom] Or Forms![FilterForm]![FFrom] is Null)
AND (Dt =Forms![FilterForm]![FTo] Or Forms![FilterForm]![FTo] is Null)

Both those expressions will return records as follows
TO and From have a value : records between the dates
TO has a value, From is Null : records before the To date
To is Null, From has a value : records after the From date
Both Null : Version One all non-null records in the date range, Version 2 all
records in the table.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Faraz A. Qureshi wrote:
I have a table "Trans" with fields [DT], [Acnt], [Amt]
I want a query to return records with dates in [DT] that are greater than or
equal to the date inserted in the [FilterForm]![FFrom] and less than or equal
to the date inserted in the [FilterForm]![FTo].

However, if [FilterForm]![FFrom] & [FilterForm]![FFrom] BOTH are NULL I want
ALL the records to be returned.

What would be the correct SQL syntax?
===
Thanx in advance & Best Regards,

Faraz!

.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:24 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.