hi everybody.
i'm trying to find out what you can and can't do with/in calculated
fields. any help, pointers, and/or advice would be greatly
appreciated. i'm a newbie, but i want to learn, and i've tried a lot
before posting.
here's my situation.
i have a simple form with dates on it. i have an indate and outdate
text box. i retrieve these dates via a query. the query is bound to my
form, frmdates. i have a 3rd text box that calculates the number of
days between the indate and outdate. this is called days. i can also
enter dates manually in these 2 text boxes, and the difference is
calculated in the days text box.
right now, this is how i've got it set up. in my query, i created the
calculated field, days.
Days: [OutDate]-[InDate])
this works fine. but where i run into trouble is when the indate and
the outdate are the same. for example
indate 2/20/2004
outdate 2/20/2004
so naturally, days = 0. but i want this to be equal to 1 because i
want to capture that it was there for that 1 day. every time days = 0,
i want it to equal 1.
i've tried to write if/then statements in the field cell in the design
view of my query, but they haven't worked. here are a few of my
examples,
i really thought the 1st one would work in the field cell of my
query...
IF([OutDate]-[InDate]=0,Days:1,Days:[OutDate]-[InDate])
IF([OutDate]-[InDate]=0,tblCaseStat.Days=1,tblCaseStat.Days=
[OutDate]-[InDate])
Days: IF([OutDate]-[InDate]=0,Days:1,Days: [OutDate]-[InDate])
IF([OutDate]=[InDate],Days:1,Days:[OutDate]-[InDate])
as you can see, i tried a few variations because i wasn't sure if
access would accept the way my code was written.
i also tried adding code to some of the events on both the form and
text boxes. for example, the on current, before update, after update
events.
i've looked through my books, but their if/then examples deal with
text, not numbers. so i don't think i need the quotes with numbers,
right.
can you use calculated fields like this in expressions. do you just
refer to them like fields from your table. do you have to do the
calculation 1st before you can refer to it.
i guess it's the colon that throws me off. can you use a colon like
this or an equals sign.
IF([OutDate]-[InDate]=0,Days:1,Days:[OutDate]-[InDate])
should these be colons or equals signs.
thanks,
miguel 1 5375
You could use a text box with ControlSource of:
=IIF([OutDate]-[InDate]=0, 1, [OutDate]-[InDate])
Note the use of Immedate If.
But if you want to count the same date as a day, you may want to count both
days inclusive? That would mean that if InDate and OutDate were 1 day apart,
you would count both days (so the answer would be 2)?
You may also want to use DateDiff(). Particularly if there are time
components in the field, there can be a difference. For example, DateDiff()
returns 1 for:
? DateDiff("d", #2/23/2004 1:00am#, #2/24/2004 11:00pm#)
1
whereas subtracting the two fields returns almost 2:
? #2/24/2004 11:00pm# - #2/23/2004 1:00am#
1.91666666667152
For general suggestions on ensuring Access understands your calculated
fields, see:
Calcualted 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.
"Miguelito Bain" <mi***********@hotmail.com> wrote in message
news:1b**************************@posting.google.c om... i'm trying to find out what you can and can't do with/in calculated fields. any help, pointers, and/or advice would be greatly appreciated. i'm a newbie, but i want to learn, and i've tried a lot before posting.
here's my situation.
i have a simple form with dates on it. i have an indate and outdate text box. i retrieve these dates via a query. the query is bound to my form, frmdates. i have a 3rd text box that calculates the number of days between the indate and outdate. this is called days. i can also enter dates manually in these 2 text boxes, and the difference is calculated in the days text box.
right now, this is how i've got it set up. in my query, i created the calculated field, days.
Days: [OutDate]-[InDate])
this works fine. but where i run into trouble is when the indate and the outdate are the same. for example
indate 2/20/2004 outdate 2/20/2004
so naturally, days = 0. but i want this to be equal to 1 because i want to capture that it was there for that 1 day. every time days = 0, i want it to equal 1.
i've tried to write if/then statements in the field cell in the design view of my query, but they haven't worked. here are a few of my examples,
i really thought the 1st one would work in the field cell of my query...
IF([OutDate]-[InDate]=0,Days:1,Days:[OutDate]-[InDate])
IF([OutDate]-[InDate]=0,tblCaseStat.Days=1,tblCaseStat.Days= [OutDate]-[InDate])
Days: IF([OutDate]-[InDate]=0,Days:1,Days: [OutDate]-[InDate])
IF([OutDate]=[InDate],Days:1,Days:[OutDate]-[InDate]) as you can see, i tried a few variations because i wasn't sure if access would accept the way my code was written.
i also tried adding code to some of the events on both the form and text boxes. for example, the on current, before update, after update events.
i've looked through my books, but their if/then examples deal with text, not numbers. so i don't think i need the quotes with numbers, right.
can you use calculated fields like this in expressions. do you just refer to them like fields from your table. do you have to do the calculation 1st before you can refer to it.
i guess it's the colon that throws me off. can you use a colon like this or an equals sign.
IF([OutDate]-[InDate]=0,Days:1,Days:[OutDate]-[InDate])
should these be colons or equals signs. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: MX1 |
last post by:
I have query2 that sums a set of fields from query1. Works fine. However,
when I try to add two of the calculated fields from query2, I get prompted
for the label I gave the fields. I just hit...
|
by: Wayne Aprato |
last post by:
I have a simple database which was originally written in Access 97.
When converted to Access 2000 file format it ran flawlessly in Access
2002. I've just tried to run it in Access 2003 and I am...
|
by: Bob |
last post by:
Hi Everybody
Difficult question
Has anyone else used the "Using the Tab control as a container"
database example that comes with the above book chapter 7 on the
accompanying disc. It is a...
|
by: Del |
last post by:
Thanks in advance for any help.
I have a database that was created in Access 2000. Several users have
been upgraded to Access 2003. Since upgrading to 2003 we have noticed
that one of the...
|
by: Ruben Baumann |
last post by:
Just wondered if anyone has had occasion to use, or does use, FileMaker, or
Raining Data's Omnis, or Alpha5's software, and how they compare with
Access?
Ruben
| |
by: TC |
last post by:
I have an Access database application with a lot of custom row
functions written in VBA. In other words, a lot of queries contain
calculated fields which use functions defined in the modules.
I...
|
by: alexandre.brisebois |
last post by:
Hi, I am using access 2003, I would like to know if there is an option
to reorganize the tables in a maner that is readable, as we can do in
sql sever 2000 or 2005.
I have been given a database...
|
by: Deac |
last post by:
I have two Access 2003 tables, one has a "Zone" and "Lot1SqFt" that
changes with each record. (8,000+ records)
A portion of this table:
CustomerID ZONE Lot1SqFt SqFtPrice ...
|
by: OzNet |
last post by:
I have a query (with calculated fields) in Access (2007) and the data changes depending on the dates and staff person selected. I need to produce a series of graphs based on the data in this query...
|
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,...
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |