Calculating by Date

joe31709

Registered User.
Local time
Today, 13:34
Joined
May 12, 2003
Messages
54
Here is what I want to do.

I want to create something that will add hours to a field by dates.

Like if today was a pay period it would add 8 hours to the total hours of leave.

If leave was 8 then after the pay period it would be 16.

Any help would be appreciated.

Joe:
 
You could achieve this through VBA, unless you want to actually have a query to run instead. Do you want the system to automatically process the calculation or only when the query is triggered?
If the query is only run once every pay day, then you could use the query builder to create an UPDATE query that would take the total amt in the leave field and add 8 to it.
Here is sample SQL

UPDATE Table1 SET Table1.Leave = Table1!Leave+"8";

Table1 Contains the field that holds the total amt of leave time acquired. Running this update query adds 8 to the existing number in that field regardless of the total already existing.
The problem is that you could inadvertently run the query multiple times within a pay period giving everyone 16 or more hrs. A second field containing a date would be helpful. You would compare the date in the table against today’s date and if there were a 14+ difference (for a bi-weekly pay schedule) then the update would run, otherwise it would not update the total leave hrs. This could be done with a DATEDIFF statement in the Criteria filed OR a where statement on the end of the SQL clause.

UPDATE Table1 SET Table1.Leave = [Table1]![Leave]+8
WHERE ((DateDiff("d",[Table1]![LastUpdate],Now())>=14));

From there the last thing you would have to worry about is updating the date field to the current date of the last successful update. You could go about this many ways, and I am sure you’ll get a few suggestions. Mine would be VBA behind a command button that triggers the query. First have it assign the current value in the total leave to a variable, then run the query, and if the variable = total leave then nothing happens, else set LastUpdate to today’s date.


Hope this is of some help. :D
 

Users who are viewing this thread

Back
Top Bottom