OK, Changing Time_In and Time_Out to general date format helped. It took a while to get it, but I finally got it working right, somewhat. Problem now is that I get a screwy return for Hrs_Worked. Employee worked from 8 am to Midnight. 16 hours, right? Well I’m getting 15.9999999999418 back. The rest of the code I have works fine (in other words “Earned” is returning $112.00, which is correct in spite of the 15.9999…..
Here’s what I have:
Fields: [Time In], [Time Out], [Hrs Worked], [Call Pay], [# Cases], [Earned]. (That’s the tab order also.)
On Table: Time in & Out are Date/Time-General Date format. Hrs Worked is Text. Call pay is yes/no. Earned is Currency.
Format on form: Time in & Out are Medium time. Hrs worked is #.# with two decimals places (Don’t ask me why, it’s been so long since I created the db that I don’t remember). Call Pay (checkbox) and # Cases (textbox) have no format. Earned is currency.
Assumptions:
1. Employee earns $30.00/hr. unless “call pay” is checked true in which case employee earns $7.00/hr.
2. If employee is being paid “Case Pay”, the employee is paid $300.00/case regardless of hours worked or if call pay is true or false. So “Earned" is always [# Cases] * 300.
Here’s what I have for code: (Beware the following may appear dysfunctional! Experienced developers may want to turn away!)
Private Sub Time_Out_Exit(Cancel As Integer)
Hrs_Worked = ([Time_Out] - [Time_In]) * 24
End Sub
Private Sub Call_Pay_Exit(Cancel As Integer)
If Forms![frm_my_hours].Call_Pay = False Then
Earned = [Hrs_Worked] * 30
Else
Earned = [Hrs_Worked] * 7
End If
End Sub
Private Sub Number_of_Cases_Exit(Cancel As Integer)
If IsNull(Forms![frm_my_hours].Number_of_Cases) Then
Earned = [Earned]
Else
Earned = [Number_of_Cases] * 300
End If
End Sub
Any opinions on what's wrong and how I can fix it or make the logic better in general? One last thing; I'm thinking of changing [Call Pay] to an option group with [regular pay],[call pay] and [case pay] as options that drive the calculation logic. I'm thinking this may improve or even maybe simply things.
Grateful for any help.
[This message has been edited by Stephenn (edited 03-30-2002).]