473,665 Members | 2,827 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Microsoft Access Calculated Fields

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,tblCaseS tat.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
Nov 12 '05 #1
1 5387
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.9166666666715 2

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.goo gle.com...

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,tblCaseS tat.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.

Nov 12 '05 #2

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

Similar topics

5
2030
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 enter and it gives me my data. Any thoughts regarding why I'd get prompted for the field name on a caluclated field when I try to use it in another calcuated field? thanks! :)
4
2128
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 seeing the following behaviour: Some of the fields on the continuous main form which is a list of jobs with their related details "flicker". While this is going on the form seems to function as it should and isn't locked up. If I click and hold...
5
1469
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 brilliant piece of design that I have used in 2 previous projects and they have worked beautifully. What it does is set up the tabs in a container with a different tab
0
1536
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 calculated fields are not being populated. The database is a samll invoicing database, on the form we have columns call Unit Cost. This is the actual cost of the part and is pulled from our parts master table and is displayed in a subform whick is...
7
2158
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
22
3797
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 am now thinking about upgrading the database from Access to SQL Server. If I do, how can I implement the custom row functions? Is Visual Basic integrated with SQL Server just as it is with Access? Or does T-SQL in SQL Server offer the...
4
6395
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 to look a and I am loosing tremendious amounts of time trying to organize it so that I could view it. Regards, Alexandre Brisebois
2
1479
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 TotalPrice 21 2 27100 $1,599.00 $1,979.00 37 4 15475 $1,068.00 $1,392.00 366 1 17190 $1,187.00 $1,292.00
15
5244
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 and it seems to me that Excel is far easier to create graphs than Access. When I use the Get External Data feature of Excel and the dialog box with the tables and queries appears, the query I need is not listed. Is this because the query has...
0
8348
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,...
0
8863
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8549
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
8636
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7376
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
6187
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
4186
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
4356
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.