I have created a form for time entry that calculates regular time to 40 hours, OT for over 40 hours. These functions work.
However, I have added a check box "Holiday", when this is checked, the form should fill in "213" as the PayID (0=Regular Time, 1=OT and 213=Double time). This function won't work.
Here is the code I have written so far......
On Error GoTo Err_Sub
Dim rs As DAO.Recordset
Dim DB As DAO.Database
Dim SQL
Dim RegularHours
Dim OvertimeHours
Dim HoursWorked
Dim WTDHours
Dim WTDRegularHours
Dim TodayRegularHours
If IsDate(Me.WorkDate) And IsNumeric(Me.EmployeeID) And Me.ProjectNoCB <> "" And IsNumeric(Me.CostCodeCB) And IsNumeric(Me.Units) And Me.DefaultBillType <> "" Then
Set DB = CurrentDb
Set rs = DB.OpenRecordset("SELECT * FROM tblemployees WHERE EmployeeID = " & Me.EmployeeID, dbOpenForwardOnly)
If DCount("EmployeeID", "tbltimeentry", "EmployeeID = " & Me.EmployeeID & " and WorkDate = #" & Me.WorkDate & "#" & _
" AND ProjectNo='" & Me.ProjectNoCB & "' AND Phase='" & Me.PhaseCB & "' AND ActivityCode='" & Me.CostCodeCB & "'") > 0 Then
If MsgBox("You have already entered time for this date for this employee, job, phase, activity code..... Would you like to overwrite this information?", vbYesNo, "Confirm Overwriting Information") = vbYes Then
' DELETE all records for this employee for the day entered, so we don't have duplicates
SQL = "DELETE FROM tbltimeentry " & _
"WHERE EmployeeID = " & Me.EmployeeID & " and WorkDate = #" & Me.WorkDate & "#" & _
" AND ProjectNo='" & Me.ProjectNoCB & "' AND Phase='" & Me.PhaseCB & "' AND ActivityCode='" & Me.CostCodeCB & "'"
DB.Execute SQL
Else
Exit Sub
End If
Else
End If
WTDHours = DSum("Units", "tbltimeentry", "EmployeeID = " & Me.EmployeeID & _
" AND PayID in ('0','1') AND WorkDate BETWEEN #" & GetWeekStartDate(Me.WorkDate) & _
"# AND #" & GetWeekEndDate(Me.WorkDate) & "#")
WTDRegularHours = DSum("Units", "tbltimeentry", "EmployeeID = " & Me.EmployeeID & _
" AND PayID = '0' AND WorkDate BETWEEN #" & GetWeekStartDate(Me.WorkDate) & _
"# AND #" & GetWeekEndDate(Me.WorkDate) & "#")
TodayRegularHours = DSum("Units", "tbltimeentry", "EmployeeID = " & Me.EmployeeID & _
" AND PayID = '0' AND WorkDate = #" & Me.WorkDate & "#")
If IsNull(WTDHours) Then
WTDHours = 0
End If
If IsNull(WTDRegularHours) Then
WTDRegularHours = 0
End If
If IsNull(TodayRegularHours) Then
TodayRegularHours = 0
End If
HoursWorked = Me.Units
RegularHours = 0
If Me.DefaultBillType = "z" Then
If Me.Holiday <> 0 Then
SQL = "INSERT INTO tbltimeentry (EmployeeID, JobNumber, ActivityCode, WorkDate, Phase, " & _
"PayID, Units, DefaultBillType, Description) " & _
"VALUES (" & Me.EmployeeID & ",'" & Me.ProjectNoCB & "','" & Me.CostCodeCB & _
"',#" & Me.WorkDate & "#,'" & Me.PhaseCB & "','213'," & RegularHours & _
",'" & Me.DefaultBillType & "','" & Me.Description & "')"
DB.Execute SQL
End If
If RegularHours > 0 Then
SQL = "INSERT INTO tbltimeentry (EmployeeID, ProjectNo, ActivityCode, WorkDate, Phase, " & _
"PayID, Units, DefaultBillType, Description) " & _
"VALUES (" & Me.EmployeeID & ",'" & Me.ProjectNoCB & "','" & Me.CostCodeCB & _
"',#" & Me.WorkDate & "#,'" & Me.PhaseCB & "','0'," & RegularHours & _
",'" & Me.DefaultBillType & "','" & Me.Description & "')"
DB.Execute SQL
End If
OvertimeHours = HoursWorked - RegularHours
If OvertimeHours > 0 Then
SQL = "INSERT INTO tbltimeentry (EmployeeID, ProjectNo, ActivityCode, WorkDate, Phase, " & _
"PayID, Units, DefaultBillType, Description) " & _
"VALUES (" & Me.EmployeeID & ",'" & Me.ProjectNoCB & "','" & Me.CostCodeCB & _
"',#" & Me.WorkDate & "#,'" & Me.PhaseCB & "','1'," & OvertimeHours & _
",'" & Me.DefaultBillType & "','" & Me.Description & "')"
DB.Execute SQL
End If
Else
If WTDHours < 40 Then
If WTDHours + HoursWorked <= 40 Then
RegularHours = HoursWorked
Else
RegularHours = 40 - WTDHours
End If
SQL = "INSERT INTO tbltimeentry (EmployeeID, ProjectNo, ActivityCode, WorkDate, Phase, " & _
"PayID, Units, DefaultBillType, Description) " & _
"VALUES (" & Me.EmployeeID & ",'" & Me.ProjectNoCB & "','" & Me.CostCodeCB & _
"',#" & Me.WorkDate & "#,'" & Me.PhaseCB & "','0'," & RegularHours & _
",'" & Me.DefaultBillType & "','" & Me.Description & "')"
DB.Execute SQL
End If
OvertimeHours = HoursWorked - RegularHours
If OvertimeHours > 0 Then
SQL = "INSERT INTO tbltimeentry (EmployeeID, ProjectNo, ActivityCode, WorkDate, Phase, " & _
"PayID, Units, DefaultBillType, Description) " & _
"VALUES (" & Me.EmployeeID & ",'" & Me.ProjectNoCB & "','" & Me.CostCodeCB & _
"',#" & Me.WorkDate & "#,'" & Me.PhaseCB & "','1'," & OvertimeHours & _
",'" & Me.DefaultBillType & "','" & Me.Description & "')"
DB.Execute SQL
End If
End If
rs.close
Else
MsgBox "You have to fill in all boxes before clicking the SAVE button!"
DoCmd.CancelEvent
End If
CheckPriorTimeEntries
Set rs = Nothing
Exit_Sub:
Exit Sub
Err_Sub:
DoCmd.CancelEvent
Resume Exit_Sub
End Sub
However, I have added a check box "Holiday", when this is checked, the form should fill in "213" as the PayID (0=Regular Time, 1=OT and 213=Double time). This function won't work.
Here is the code I have written so far......
On Error GoTo Err_Sub
Dim rs As DAO.Recordset
Dim DB As DAO.Database
Dim SQL
Dim RegularHours
Dim OvertimeHours
Dim HoursWorked
Dim WTDHours
Dim WTDRegularHours
Dim TodayRegularHours
If IsDate(Me.WorkDate) And IsNumeric(Me.EmployeeID) And Me.ProjectNoCB <> "" And IsNumeric(Me.CostCodeCB) And IsNumeric(Me.Units) And Me.DefaultBillType <> "" Then
Set DB = CurrentDb
Set rs = DB.OpenRecordset("SELECT * FROM tblemployees WHERE EmployeeID = " & Me.EmployeeID, dbOpenForwardOnly)
If DCount("EmployeeID", "tbltimeentry", "EmployeeID = " & Me.EmployeeID & " and WorkDate = #" & Me.WorkDate & "#" & _
" AND ProjectNo='" & Me.ProjectNoCB & "' AND Phase='" & Me.PhaseCB & "' AND ActivityCode='" & Me.CostCodeCB & "'") > 0 Then
If MsgBox("You have already entered time for this date for this employee, job, phase, activity code..... Would you like to overwrite this information?", vbYesNo, "Confirm Overwriting Information") = vbYes Then
' DELETE all records for this employee for the day entered, so we don't have duplicates
SQL = "DELETE FROM tbltimeentry " & _
"WHERE EmployeeID = " & Me.EmployeeID & " and WorkDate = #" & Me.WorkDate & "#" & _
" AND ProjectNo='" & Me.ProjectNoCB & "' AND Phase='" & Me.PhaseCB & "' AND ActivityCode='" & Me.CostCodeCB & "'"
DB.Execute SQL
Else
Exit Sub
End If
Else
End If
WTDHours = DSum("Units", "tbltimeentry", "EmployeeID = " & Me.EmployeeID & _
" AND PayID in ('0','1') AND WorkDate BETWEEN #" & GetWeekStartDate(Me.WorkDate) & _
"# AND #" & GetWeekEndDate(Me.WorkDate) & "#")
WTDRegularHours = DSum("Units", "tbltimeentry", "EmployeeID = " & Me.EmployeeID & _
" AND PayID = '0' AND WorkDate BETWEEN #" & GetWeekStartDate(Me.WorkDate) & _
"# AND #" & GetWeekEndDate(Me.WorkDate) & "#")
TodayRegularHours = DSum("Units", "tbltimeentry", "EmployeeID = " & Me.EmployeeID & _
" AND PayID = '0' AND WorkDate = #" & Me.WorkDate & "#")
If IsNull(WTDHours) Then
WTDHours = 0
End If
If IsNull(WTDRegularHours) Then
WTDRegularHours = 0
End If
If IsNull(TodayRegularHours) Then
TodayRegularHours = 0
End If
HoursWorked = Me.Units
RegularHours = 0
If Me.DefaultBillType = "z" Then
If Me.Holiday <> 0 Then
SQL = "INSERT INTO tbltimeentry (EmployeeID, JobNumber, ActivityCode, WorkDate, Phase, " & _
"PayID, Units, DefaultBillType, Description) " & _
"VALUES (" & Me.EmployeeID & ",'" & Me.ProjectNoCB & "','" & Me.CostCodeCB & _
"',#" & Me.WorkDate & "#,'" & Me.PhaseCB & "','213'," & RegularHours & _
",'" & Me.DefaultBillType & "','" & Me.Description & "')"
DB.Execute SQL
End If
If RegularHours > 0 Then
SQL = "INSERT INTO tbltimeentry (EmployeeID, ProjectNo, ActivityCode, WorkDate, Phase, " & _
"PayID, Units, DefaultBillType, Description) " & _
"VALUES (" & Me.EmployeeID & ",'" & Me.ProjectNoCB & "','" & Me.CostCodeCB & _
"',#" & Me.WorkDate & "#,'" & Me.PhaseCB & "','0'," & RegularHours & _
",'" & Me.DefaultBillType & "','" & Me.Description & "')"
DB.Execute SQL
End If
OvertimeHours = HoursWorked - RegularHours
If OvertimeHours > 0 Then
SQL = "INSERT INTO tbltimeentry (EmployeeID, ProjectNo, ActivityCode, WorkDate, Phase, " & _
"PayID, Units, DefaultBillType, Description) " & _
"VALUES (" & Me.EmployeeID & ",'" & Me.ProjectNoCB & "','" & Me.CostCodeCB & _
"',#" & Me.WorkDate & "#,'" & Me.PhaseCB & "','1'," & OvertimeHours & _
",'" & Me.DefaultBillType & "','" & Me.Description & "')"
DB.Execute SQL
End If
Else
If WTDHours < 40 Then
If WTDHours + HoursWorked <= 40 Then
RegularHours = HoursWorked
Else
RegularHours = 40 - WTDHours
End If
SQL = "INSERT INTO tbltimeentry (EmployeeID, ProjectNo, ActivityCode, WorkDate, Phase, " & _
"PayID, Units, DefaultBillType, Description) " & _
"VALUES (" & Me.EmployeeID & ",'" & Me.ProjectNoCB & "','" & Me.CostCodeCB & _
"',#" & Me.WorkDate & "#,'" & Me.PhaseCB & "','0'," & RegularHours & _
",'" & Me.DefaultBillType & "','" & Me.Description & "')"
DB.Execute SQL
End If
OvertimeHours = HoursWorked - RegularHours
If OvertimeHours > 0 Then
SQL = "INSERT INTO tbltimeentry (EmployeeID, ProjectNo, ActivityCode, WorkDate, Phase, " & _
"PayID, Units, DefaultBillType, Description) " & _
"VALUES (" & Me.EmployeeID & ",'" & Me.ProjectNoCB & "','" & Me.CostCodeCB & _
"',#" & Me.WorkDate & "#,'" & Me.PhaseCB & "','1'," & OvertimeHours & _
",'" & Me.DefaultBillType & "','" & Me.Description & "')"
DB.Execute SQL
End If
End If
rs.close
Else
MsgBox "You have to fill in all boxes before clicking the SAVE button!"
DoCmd.CancelEvent
End If
CheckPriorTimeEntries
Set rs = Nothing
Exit_Sub:
Exit Sub
Err_Sub:
DoCmd.CancelEvent
Resume Exit_Sub
End Sub