473,503 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Building a query with dates

I am tring to write build a query where the outcome of a result depends
on one date being older than the other.

example
Field Name: IIf([Field Name 1]=Null,Null,IIf([Field Name 1]<[Field Name
2],[Field Name 1],Null))

However the result comes up as an "#Error". What am I doing wrong or
can you not do queries like this with dates.

Stephen

Nov 13 '05 #1
3 1336
You cannot compare a field to Null. Instead, test if it Is Null.

Additionally, Access tends to misunderstand calculated fields, so typecast
the result with CVDate(), i.e.:
CVDate(IIf([Field1] Is Null, Null, IIf([Field1] < [Field2], [Field1],
Null)))

More on the issue with Nulls:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html

More on the need to typecast:
Calculated fields misinterpreted
at:
http://allenbrowne.com/ser-45.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Spook" <st**************@sainsburys.co.uk> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I am tring to write build a query where the outcome of a result depends
on one date being older than the other.

example
Field Name: IIf([Field Name 1]=Null,Null,IIf([Field Name 1]<[Field Name
2],[Field Name 1],Null))

However the result comes up as an "#Error". What am I doing wrong or
can you not do queries like this with dates.

Stephen

Nov 13 '05 #2
it sounds like the error u're getting is from a mismatched data type.
when i tried ur sample code with a text input to the [field1] field in
ur statement, it yielded the same #ERROR result u got. there's probably
a mismactched data type somewhere, text with date, or something of the
sort.

here's the code i used.
IIf(IsNull([date1]) Or [date1]>[date2],Null,[date1])

hope this helps.

Nov 13 '05 #3


Cheers guys for the help. I have just got back from a mmeting and will
try your suggestions tomorrow.

Stephen

Nov 13 '05 #4

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

Similar topics

6
2413
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18....
8
7538
by: Donna Sabol | last post by:
First, I should start by saying I am creating a database to be used by some very impatient, non-computer literate people. It needs to be seameless in it's operation from their point of view. I...
1
1658
by: Mike Cooper | last post by:
Hi everyone, This is a tough one. I have a database full of solicitations, identifying a customer and recording initial call, first followup, second followup, etc. My boss want to be able to...
1
1439
by: ckpoll2 | last post by:
Hello, I have a form that has a text box that is a dsum run off of a query. The query is called Leave. I'm trying to make it so that the data returned from the query is between and , both are...
2
5725
by: Mark Roughton | last post by:
I have a form where the users need to view records for various criteria, one of which is a date field on which they may wish to view all related data for the selected date, for all dates upto and...
13
12995
newnewbie
by: newnewbie | last post by:
I have an Access database that I upload a data extract intoto daily. I want to create a query that will give me a list of dates that no data can be found for. E.g. there are no records created on the...
6
2774
by: dafinder | last post by:
Hello all, I am a new user of Access and have run into some problems. I am building an access form that uses multiple tables. This is what I want to do in lay mans terms. I have a form with...
4
2166
by: stpark22 | last post by:
Hello, I'm building a tracking tool using Access 2003, where my users will be entering orders that includes quantity of products sold, and cost per unit. I'm in the process of building several...
2
2457
by: markcarroll | last post by:
I have a rather complicating query (the SQL is about a page long) so I hope I can solve this without needing to get into specifics. Basically, the database I am working on has information about...
0
7287
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
7349
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
7008
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
5594
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
5022
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
4688
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
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
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 ...
0
399
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...

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.