PC Review


Reply
Thread Tools Rate Thread

calculate table field value

 
 
Portia
Guest
Posts: n/a
 
      7th Nov 2008
Is it possible to calulate a field in a table? I want to have [age] as a
field in my table, and I want it to be automatically calculated from DOB (a
field in the table) and the current date. (I know I can do this in a form or
query, but I want the field in the table).
 
Reply With Quote
 
 
 
 
Arvin Meyer [MVP]
Guest
Posts: n/a
 
      7th Nov 2008
Not only is it not possible, it's not proper database design. Your request
is one of the main reasons that it isn't advisable. What happens next year?
Does it recalculate every day?

Instead, use a query or form to calculate, which I realize is not what you
want, but is the most desirable. Keep in mind that tables really should
never be used to display or enter data. Their purpose is to store it.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"Portia" <(E-Mail Removed)> wrote in message
news:12C4304F-6213-4841-B93B-(E-Mail Removed)...
> Is it possible to calulate a field in a table? I want to have [age] as a
> field in my table, and I want it to be automatically calculated from DOB
> (a
> field in the table) and the current date. (I know I can do this in a form
> or
> query, but I want the field in the table).



 
Reply With Quote
 
fredg
Guest
Posts: n/a
 
      7th Nov 2008
On Fri, 7 Nov 2008 11:30:02 -0800, Portia wrote:

> Is it possible to calulate a field in a table? I want to have [age] as a
> field in my table, and I want it to be automatically calculated from DOB (a
> field in the table) and the current date. (I know I can do this in a form or
> query, but I want the field in the table).


Why would you wish to 'store' data that is sure to be incorrect at
least once a year?

Store the date of birth in your table, then whenever you need tha
actual age, calculate it.

In a query:
Age: DateDiff("yyyy",[DOB],Date())-Iif(Format([DOB],
"mmdd")>Format(Date(),"mmdd"),1,0)

Directly as the control source of an unbound control:
=DateDiff("yyyy",[DOB],Date())-IIf(Format([DOB],
"mmdd")>Format(Date(),"mmdd"),1,0)

Where [DOB] is the birthdate field.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      7th Nov 2008
On Fri, 7 Nov 2008 11:30:02 -0800, Portia <(E-Mail Removed)>
wrote:

> but I want the field in the table


Why?

Storing derived data such as this in your table accomplishes
three things: it wastes disk space; it wastes time (almost
any calculation will be MUCH faster than a disk fetch); and
most importantly, it risks data corruption. If one of the
underlying fields is subsequently edited, you will have data
in your table WHICH IS WRONG, and no automatic way to detect
that fact.

Just redo the calculation whenever you need it, either as a
calculated field in a Query or in the control source of a Form or a Report
textbox.
--

John W. Vinson [MVP]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate field with input from different table Andreas Microsoft Access 5 14th Dec 2009 04:13 PM
Pivot Table Calculate Field Brad Autry Microsoft Excel Worksheet Functions 1 26th Aug 2009 12:22 AM
Pivot table calculate field Adam Microsoft Excel Misc 3 5th Mar 2008 05:10 PM
Calculate next 5 numbers from table field Domino Microsoft Access Queries 2 4th Jan 2008 06:46 PM
Calculate field in Table. Cam Microsoft Access Database Table Design 2 27th Oct 2003 09:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:40 PM.