Running Total?

G

Guest

I have a form with several fields to track hours worked. I have a field called "Current Hours" and then I have seven other fields named after the days of the week ex. Mon Tue Wed Thurs Fri Sat Sun. Now, what I want to hapen is when I put a number in the Mon or Tues field for example.. that number adds to the current number in the "Current Hours" field. Any ideas? Is this an afterupdate expression. Please Advise. Thanks
 
H

hin87_at_yahoo.com

Try putting this code on the Afterupdate function for each of the days

Sub Afterupdate()
call CalculateWorkHrs
End Sub

Sub CalculateWorkHrs()
current = Mon + Tue + Wed + Thurs + Fri + Sat + Sun
End sub

and then I have seven other fields named after the days of the week ex. Mon Tue Wed Thurs Fri Sat Sun. Now, what I want to hapen is when I
put a number in the Mon or Tues field for example.. that number adds
to the current number in the "Current Hours" field. Any ideas? Is
this an afterupdate expression. Please Advise. Thanks
 
G

Guest

I get the following error: "Member already exist in an object module from which this object module drives."

And just so that im clear. I want the totals of the days of the week to be Added to the number already in Current Hours. Also, Is it possible to removes the numbers that were inputed in the days of the weeks after update?
 
P

Pieter Wijnen

I would personally go with 1 control for each WeekDay & 1 for unspecified &
add up into a locked field for the total to avoid
to many unwanted "duplicates"
If so Create 9 Controls Named Day1 Through Day9 (label them according to
your weekday calendar Sun .. Sat,Other,Total)

Create a Sub on the Form:
Sub CalcTotalHours()
Dim C as Access.Control
Dim i As Integer, TotHours As Integer

Access.Application.screen.MousePointer = 11 ' I tend to avoid Docmd
whenever I Can ;-)
For i =1 To 8 ' I'm lazy .....
Set C = Me.Controls("Day" & i)
TotHours = TotHours + Nz(C.Value,0) ' Must Handle Null's correctly
C.Value = Null ' if you want to clear it
Next
Me.Controls("Day9").Value = TotHours
Set C = Nothing ' I always try to make sure to realease all pointers to
objects - but usually fail miserably due 2 lack of time..
End Sub

Now you have two options (3 if you convert it to a function & use it as a
controlsource for "Day9")
1) Create an After_Update Event Proc for days 1..8 & place a ref to the sub
there
2) Create a Command Button & put it in the Click Events Procedure ...

HTH

Pieter




Joan said:
I get the following error: "Member already exist in an object module from
which this object module drives."
And just so that im clear. I want the totals of the days of the week to
be Added to the number already in Current Hours. Also, Is it possible to
removes the numbers that were inputed in the days of the weeks after update?
 

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