Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write calculated field to table 1

Status
Not open for further replies.

priac

Technical User
Feb 8, 2002
47
US
I will start by saying, I am a pilot not a programmer.
I have a form opened that is called mission Details and it is using a table called MissionDetails. When the aircraft start time and stop are enter, that is stored in MissionDetails table. These times are entered as 10:31, 14:20 etc. I have a calculated (text Box ) on the form that makes a decimal from that " =(([StopTime]-[StartTime])*24) ". It is displayed in a (text Box) called "timeToFraction". The table " MissionDetails " has a field called "timeToFraction" I need to write that number(timeToFraction) to the table when it is updated in the "TimeToFraction" text Box. I have no idea where to start.

Aubrey Price
Chief Pilot
Airborne Imaging Inc.
 
Just my opinion, but I would NOT keep any calculated field in a table.
Let's say you do, and you have data like this:

[pre]
StartTime StopTime timeToFraction
10:30 14:30 4:00
12:00 13:30 1:30[red]
15:00 16:30 7:15[/red]
[/pre]
First 2 records make sense, what about the last record? Which data is correct? And which data is garbage? You will never know.

Create a query and calculate [tt]timeToFraction[/tt] in the query. It will always be correct.


---- Andy

There is a great need for a sarcasm font.
 
I'm a programmer not a pilot ;-) so I would not store the calculated value. It just creates undue maintenance since you can always calculate the value in a control source like you have already done or in a query.

One of the needs for storing a calculated value is in an order detail table where discounts or prices vary over time.

If you really think you need to store the value, you could add some code to the After Update event of the start and stop fields like the following which uses a single sub that is called from each controls after update:

Code:
Private Sub StartTime_AfterUpdate()
    CalcTime
End Sub
Private Sub StopTime_AfterUpdate()
    CalcTime
End Sub
Sub CalcTime()
    Me.TimeToFraction = ([StopTime] - [StartTime]) * 24
End Sub

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top