473,657 Members | 2,634 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 1342
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.c o.uk> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.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
2422
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. I need a query that will return the c date for TypeID 18 if it exist else the date for TypeID 1, for all jobs. the table structure is the following Job TypeID
8
7564
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 want them to do as little as possible when they run their reports. I have a crosstab query that displays usage of items for each month. It looks pretty much like this: ITEM DESC UM 12/02 1/03 2/03 3/03 ...ETC. 1 Solution ...
1
1667
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 generate a report showing a list of customer who were call between two different dates that he types into a form. That, I have done. My boss types in his two dates, the SQL statement searches through the follow-up call fields for a date
1
1450
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 values entered by the user. I tried doing this in the query, but it gave me an error. Also, the form's control source is another table, so I don't think that I can do anything in the query builder for the form. The formula for the text box is......
2
5730
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 icluding the selected date or all records on or after the selected date The user selects either "=", >=" or "<=" from a combo box and then a date from another combobox. The combination of thse two choices is then set in an unbound textbox so...
13
13030
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 weekends, hence weekend dates will be in the list generated by this query. By creating such a query I want to ensure integrity of my data, e.i.looking at this query from time to time will give me an idea that on such and such date I might have...
6
2783
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 3 sets of combo boxes. The first box I want the user to select a protocol that they wish to display.Next I have 2 combo boxes that display dates. I have 3 tables, one with the date ranges, one with the protocols and one with all the data. I want...
4
2178
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 instant reports where they can click on a control without having to specific any criterias such as data ranges and pull up an instant report What I'm having trouble with is building reports that will compute totals by certain dates (Totals For...
2
2465
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 investment firms, and what companies they hold shares of. I set up the query to find all the stocks that a specified company held for the most recent date. But we need to display data for the past dates as well. The way I got the most recent date...
0
8319
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8512
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7347
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6175
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4171
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
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 we have to send another system
2
1732
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.