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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculating a field value by adding other field values 1

Status
Not open for further replies.

mmaddox

IS-IT--Management
May 22, 2002
53
US
I have a table which contains “hours worked” for different trades (electrical, plumbing…) there are 14 of them. A single record has a field for each trade. There is also a field for total hours, which is the total of all trade’s hours for that record. I know this could be calculated at runtime – but the user wants it as a field to simplify reporting

I am struggling with how to keep the total hours calculated in the table. On the form I have an “After Update” event which looks like below for each of the trades. txttotaltime is the lable of the textbox that writes data to the total hours field, totaltime.

Private Sub txtpltotal_AfterUpdate()
txttotaltime.Value = [txteltotal] + [txtpltotal]
End Sub

I’m using that exact same code for each of the 14 trade’s afterupdate time entries.

The questions are: is there a way to create a function that could to do the addition, then just call that function in the AfterUpdate event on the form?

And – the calculation only works if there is a value in every one of the trades hours fields. I have the table set up to give a 0 default value, but if the user deletes the 0, it will not add. I suppose the function would need to check for null or value less than 1, and assign it a 0 if that is true.

Any help would be appreciated, even if someone has a completely different idea of how to do this.
 
Hi

Oh dear

You have already broken the rules of good table design by having repeating fields for hours worked, now youa re going to break them again by storing redundant information

don't do it

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Ok, thanks for the advice. I guess I will split the table up and go from there.

Thanx.

I gave you a star for not encouraging me to head down the wrong path.
 
Hi

Thanks for the star, hope you get sorted, a good friend of mine has the irratating saying "it is never easier to do it wrong", one reason why it is irratating is because it is so true!

Good luck



Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top