Time calculation

P

Paul

Hi gang,

I've already been here:

http://www.mvps.org/access/datetime/date0004.htm

I have 2 time fields, "Time In" and "Time Out". I have a
third field, a number field, that is to receive a
difference of the 2. Like I said, I tried the expression
from the link above and got this error:

"The database engine does not recognize either the
field "Time In" in a validation expression, or the
default value in the table "Task" "

I'm assuming the expression from the link is to go into
the Default Value section of the intemded field. Can
anyone please explain to me,like a 4-year old, what I did
incorrectly??

Thanks very much,
Paul
 
R

Rick Brandt

Paul said:
Hi gang,

I've already been here:

http://www.mvps.org/access/datetime/date0004.htm

I have 2 time fields, "Time In" and "Time Out". I have a
third field, a number field, that is to receive a
difference of the 2. Like I said, I tried the expression
from the link above and got this error:

"The database engine does not recognize either the
field "Time In" in a validation expression, or the
default value in the table "Task" "

I'm assuming the expression from the link is to go into
the Default Value section of the intemded field.

No, it goes in the ControlSource (assuming you're talking about a Form which
actually "controls", not "fields").
 
G

Guest

Actually, Rick, I was talking not about forms, as I
hadn't even progressed taht far :) I did kind of a rush
job on this, and am entering data right at the datasheet
level of the table itself. That's why I was hoping I
could utiize the Format fucntion of the expression
builder attached to the Default Value of the field itself
in the table.

Does all this mean that function won't work on that level?

Thanks again for your time.
Paul
 
J

John Vinson

Hi gang,

I've already been here:

http://www.mvps.org/access/datetime/date0004.htm

I have 2 time fields, "Time In" and "Time Out". I have a
third field, a number field, that is to receive a
difference of the 2. Like I said, I tried the expression
from the link above and got this error:

"The database engine does not recognize either the
field "Time In" in a validation expression, or the
default value in the table "Task" "

Reread the explanation on the website.

You cannot and should not store this time difference in a Table - *at
all*.

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 just as you're now doing it -
in the control source of a Form or a Report textbox.


John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
J

Jeff Boyce

Paul

To add to Rick's and John's suggestions, I would ask a clarifying question.
What data type are you using to hold the "time" values. I'm unaware of an
Access datatype for "time" only.
 
G

goofy

These answers seem very complicated.
Assuming you have TimeIn and TimeOut in TableName,
the following functions will readily generate
the difference:
NetWorkDays([TableName]![timeIn],[TableName]![timeOut]), if you like, or
DateDiff("s",[TableName]![time1],[TableName]![time2]) for seconds, "d" for
days, etc.

You definitely should NOT store this, as the number can readily be
calculated from
information in the table.

Scott
 
D

Douglas J. Steele

Um, there's no NetWorkDays function in Access, Scott.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



goofy said:
These answers seem very complicated.
Assuming you have TimeIn and TimeOut in TableName,
the following functions will readily generate
the difference:
NetWorkDays([TableName]![timeIn],[TableName]![timeOut]), if you like, or
DateDiff("s",[TableName]![time1],[TableName]![time2]) for seconds, "d" for
days, etc.

You definitely should NOT store this, as the number can readily be
calculated from
information in the table.

Scott

Paul said:
Hi gang,

I've already been here:

http://www.mvps.org/access/datetime/date0004.htm

I have 2 time fields, "Time In" and "Time Out". I have a
third field, a number field, that is to receive a
difference of the 2. Like I said, I tried the expression
from the link above and got this error:

"The database engine does not recognize either the
field "Time In" in a validation expression, or the
default value in the table "Task" "

I'm assuming the expression from the link is to go into
the Default Value section of the intemded field. Can
anyone please explain to me,like a 4-year old, what I did
incorrectly??

Thanks very much,
Paul
 
P

pvdalen

Hey John,

Just wanted to let you know you convinced me. I removed the "Hours" field
in the database and now emply calculatons where I need them. I think I
balked initially at that solution, because I have separate date and time
fields, and it seemed like a pain in the ass, but simple concatenation worked
fine.

Thanks again, John. You're always a big help.

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top