I am making a report that displays employee's hours and want a field in the details that also displays each employee's hours to date. I think I solved it by writing code in a module. This module is called from the On Print event of the details section of the report. Here is some of the code in the module:
Option Compare Database
Public Gbl_Run_Sum As Double
Public Gbl_RunSum1, Gbl_RunSum2, Gbl_RunSum3, Gbl_RunSum4 As Double
Public Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
If Me.EmployeeID = 1 Then
Gbl_Run_Sum1 = Gbl_Run_Sum1 + Me.HoursWorked
Gbl_Run_Sum = Gbl_Run_Sum1
End If
If Me.EmployeeID = 2 Then
Gbl_Run_Sum2 = Gbl_Run_Sum2 + Me.HoursWorked
Gbl_Run_Sum = Gbl_Run_Sum2
End If
If Me.EmployeeID = 3 Then
Gbl_Run_Sum3 = Gbl_Run_Sum3 + Me.HoursWorked
Gbl_Run_Sum = Gbl_Run_Sum3
End If
If Me.EmployeeID = 4 Then
Gbl_Run_Sum4 = Gbl_Run_Sum4 + Me.HoursWorked
Gbl_Run_Sum = Gbl_Run_Sum4
End If
Me.HoursTotal = Gbl_Run_Sum
End Sub
The problem I have is as it is run the values saved in the variables aren't retained as the program continues. I'm sure it's because the sub ends after each detail and the values are reset. Is there some way to retain the values in the variables after the sub ends until I'm ready for it to reset?
Option Compare Database
Public Gbl_Run_Sum As Double
Public Gbl_RunSum1, Gbl_RunSum2, Gbl_RunSum3, Gbl_RunSum4 As Double
Public Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
If Me.EmployeeID = 1 Then
Gbl_Run_Sum1 = Gbl_Run_Sum1 + Me.HoursWorked
Gbl_Run_Sum = Gbl_Run_Sum1
End If
If Me.EmployeeID = 2 Then
Gbl_Run_Sum2 = Gbl_Run_Sum2 + Me.HoursWorked
Gbl_Run_Sum = Gbl_Run_Sum2
End If
If Me.EmployeeID = 3 Then
Gbl_Run_Sum3 = Gbl_Run_Sum3 + Me.HoursWorked
Gbl_Run_Sum = Gbl_Run_Sum3
End If
If Me.EmployeeID = 4 Then
Gbl_Run_Sum4 = Gbl_Run_Sum4 + Me.HoursWorked
Gbl_Run_Sum = Gbl_Run_Sum4
End If
Me.HoursTotal = Gbl_Run_Sum
End Sub
The problem I have is as it is run the values saved in the variables aren't retained as the program continues. I'm sure it's because the sub ends after each detail and the values are reset. Is there some way to retain the values in the variables after the sub ends until I'm ready for it to reset?