Hi everyone, I appreciate all the responses to Posts, I have certainly learnt a few things since joining. Thanks
I have a form that calcs leave values for an employee. These calcs work fine on the form. So I thought I could use them in a report. I take it that the DSum function on a query works alright from a report?
Anyway I'm getting the dreaded 'Error 2001 - You canceled the previous Operation. I've done spurious research on this error and can't see where it's nobbling me. unless it's the DSum issue I mentioned above
Also how does one post code in a window that I have seen?
My calcs are: (Error line in Red)
Private Sub GroupHeader1_Format(Cancel As Integer, FormatCount As Integer)
' Run Calcs here for Leave other than Sick Leave.
If IsNull(EmpStartDate) Then
DaysWorked = 0
Else
DaysWorked = DateDiff("d", EmpStartDate, Now)
End If
' Calc number of days between Employee Start Date and Now
TotalLeaveAlloc = DaysWorked * (Me!AnnualLeaveDue / 365)
' Me.AllDaysWorked = TotalLeaveAlloc 'Just to see what it is!
' Divide Allocated days by 365 and multiply by number of days worked
' to get number of holidays due in total
If IsNull(DSum("[DaysTaken]", "[qryLeaveRecords]", "[LeaveType]<>'Sick' And [tblEmployees]![EmployeeID] = [tblLeaveRecord]![EmployeeID]")) Then
Me.Taken01 = 0
Else
Me.Taken01 = DSum("[DaysTaken]", "[qryLeaveRecords]", "[LeaveType]<>'Sick' And [tblEmployees]![EmployeeID] = [tblLeaveRecord]![EmployeeID]")
End If
' Calculates the number of leave days taken from leave records in database based on qryLeaveRecords
' Used IsNull to check if there are no records found - set calc result to zero
' Display this on screen
If IsNull(Me.LeaveAccrued) Then
Me.Bal01 = TotalLeaveAlloc - Me.Taken01
Else
Me.Bal01 = TotalLeaveAlloc - (Me.Taken01 + Me.LeaveAccrued)
End If
' Check if there is any Accrued Leave [reduces the need to load historical Leave Records] and subtract them
' Display Balance
' Run Calcs for Sick Leave here.
If IsNull(DSum("[DaysTaken]", "[qrySickLeaveRecs]", "[tblEmployees]![EmployeeID] = [tblLeaveRecord]![EmployeeID]")) Then
Me.Taken02 = 0
Else
Me.Taken02 = DSum("[DaysTaken]", "[qrySickLeaveRecs]", "[tblEmployees]![EmployeeID] = [tblLeaveRecord]![EmployeeID]")
End If
' Calculates the number of leave days taken from leave records in database based on qrySickLeaveRecs
' Used IsNull to check if there are no records found - set calc result to zero
' Display this on screen
Me.Bal02 = Me.SickLeaveDue - Me.Taken02
' Display Sick Leave Balance
End Sub
Many thanks
I have a form that calcs leave values for an employee. These calcs work fine on the form. So I thought I could use them in a report. I take it that the DSum function on a query works alright from a report?
Anyway I'm getting the dreaded 'Error 2001 - You canceled the previous Operation. I've done spurious research on this error and can't see where it's nobbling me. unless it's the DSum issue I mentioned above
Also how does one post code in a window that I have seen?
My calcs are: (Error line in Red)
Private Sub GroupHeader1_Format(Cancel As Integer, FormatCount As Integer)
' Run Calcs here for Leave other than Sick Leave.
If IsNull(EmpStartDate) Then
DaysWorked = 0
Else
DaysWorked = DateDiff("d", EmpStartDate, Now)
End If
' Calc number of days between Employee Start Date and Now
TotalLeaveAlloc = DaysWorked * (Me!AnnualLeaveDue / 365)
' Me.AllDaysWorked = TotalLeaveAlloc 'Just to see what it is!
' Divide Allocated days by 365 and multiply by number of days worked
' to get number of holidays due in total
If IsNull(DSum("[DaysTaken]", "[qryLeaveRecords]", "[LeaveType]<>'Sick' And [tblEmployees]![EmployeeID] = [tblLeaveRecord]![EmployeeID]")) Then
Me.Taken01 = 0
Else
Me.Taken01 = DSum("[DaysTaken]", "[qryLeaveRecords]", "[LeaveType]<>'Sick' And [tblEmployees]![EmployeeID] = [tblLeaveRecord]![EmployeeID]")
End If
' Calculates the number of leave days taken from leave records in database based on qryLeaveRecords
' Used IsNull to check if there are no records found - set calc result to zero
' Display this on screen
If IsNull(Me.LeaveAccrued) Then
Me.Bal01 = TotalLeaveAlloc - Me.Taken01
Else
Me.Bal01 = TotalLeaveAlloc - (Me.Taken01 + Me.LeaveAccrued)
End If
' Check if there is any Accrued Leave [reduces the need to load historical Leave Records] and subtract them
' Display Balance
' Run Calcs for Sick Leave here.
If IsNull(DSum("[DaysTaken]", "[qrySickLeaveRecs]", "[tblEmployees]![EmployeeID] = [tblLeaveRecord]![EmployeeID]")) Then
Me.Taken02 = 0
Else
Me.Taken02 = DSum("[DaysTaken]", "[qrySickLeaveRecs]", "[tblEmployees]![EmployeeID] = [tblLeaveRecord]![EmployeeID]")
End If
' Calculates the number of leave days taken from leave records in database based on qrySickLeaveRecs
' Used IsNull to check if there are no records found - set calc result to zero
' Display this on screen
Me.Bal02 = Me.SickLeaveDue - Me.Taken02
' Display Sick Leave Balance
End Sub
Many thanks