This would be an example of one of the functions to give you an idea of perhaps why it takes 10 minutes to calculate 15 of these times 200 employees (the first one that i mentioned in the prior post - which the Base Salary function would rely on):
Function empStep(empid As Integer, posNum As Byte, asofdate As Date)
Dim db As dao.Database, rst As dao.Recordset, strSQL As String, rst1 As dao.Recordset, strSQL1 As String
Set db = CurrentDb()
'OPEN EMPLOYEE POSITIONS
strSQL1 = "SELECT * FROM tblEmployeePositions " & _
"WHERE [lngEmpID] = " & empid & " AND [lngPstnNmbr] = " & posNum & " AND [dtPstnDtStrt] <=#" & asofdate & "# AND nz([dtPstnDtEnd],#" & asofdate & "#) >=#" & asofdate & "#"
Set rst1 = db.OpenRecordset(strSQL1, dbOpenDynaset)
With rst1
Dim YrsInPos As Single, StpOvrd As Byte, posStrt As Date, posEnd As Date
'Find Years in Position
YrsInPos = (Nz(.Fields("dtPstnDtEnd"), asofdate) - .Fields("dtPstnDtStrt")) / 365.25
'Find Position Start Date
posStrt = .Fields("dtPstnDtStrt")
If .Fields("blnOvrd") = -1 Then
'Override Applies
StpOvrd = .Fields("lngStpOvrd")
Else
'No Override
StpOvrd = 0
End If
End With
'Find Parameter Rules
If empUnion(empid, asofdate) = 0 And rst1.Fields("blnOvrd") = 0 Then
empStep = "N/A"
Else
strSQL = "SELECT * FROM tblStepParameters " & _
"WHERE [lngUnnID] = " & empUnion(empid, asofdate)
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
Dim strCriteria As String
'Union not in Step Paramaters Table
If (rst.EOF = True) And (rst.BOF = True) Then
If rst1.Fields("blnOvrd") = -1 Then
empStep = StpOvrd
Else
empStep = "N/A"
End If
'Union IS in step Paramaters Table
Else
Dim rst2 As dao.Recordset, strSQL2 As String
Select Case Nz(rst.Fields("dtstpAnnivDt"), "N/A")
'No Anniversary Date
Case "N/A"
strCriteria = " AND [lngYrsMin] <=(" & YrsInPos & " + " & StpOvrd & ") AND nz([lngYrsMax]," & YrsInPos & " + " & StpOvrd & ")>= " & YrsInPos & " + " & StpOvrd
strSQL2 = "SELECT * FROM tblStepParameters " & _
"WHERE [lngUnnID] = " & empUnion(empid, asofdate) & strCriteria
Set rst2 = db.OpenRecordset(strSQL2, dbOpenDynaset)
'Anniversary Date
Case Else
Dim AnnivDate As Date, AnnivStep As Single
AnnivDate = DateSerial(Year(posStrt), Left(rst.Fields("dtStpAnnivDt"), 2), Right(rst.Fields("dtStpAnnivDt"), 2))
AnnivStep = ((asofdate - AnnivDate) / 365.25) + StpOvrd
strCriteria = " AND [lngYrsMin] <=" & AnnivStep & " AND nz([lngYrsMax]," & AnnivStep & ")>= " & AnnivStep & " ORDER BY tblStepParameters.lngStpNmbr;"
strSQL2 = "SELECT * FROM tblStepParameters " & _
"WHERE [lngUnnID] = " & empUnion(empid, asofdate) & strCriteria
Set rst2 = db.OpenRecordset(strSQL2, dbOpenDynaset)
rst2.MoveLast
End Select
empStep = rst2.Fields("lngStpNmbr")
rst2.Close
Set rst2 = Nothing
End If
End If
rst1.Close
Set rst1 = Nothing
If Not empUnion(empid, asofdate) = "N/A" Then
rst.Close
Set rst = Nothing
End If
End Function
I know i was pretty vague - All of the functions i'm using are relatively simple, but depend on other functions as well.
Ex.
To find someone's base salary I created a function that first finds how long theyve been in the position, and based on this number and what their contract says (another table) what "STEP" they would be within a salary range.
Another function finds all of their current positions and how long they have been in each position from one table. The salary range for said position from another table then calls the previous function to find the STEP and assigns them a base salary value.
Next, the base salary function would be used to find any stipends or longevity pay that they would have (usually a percentage of base salary)
I continuously have to call prior functions to find these numbers
On their own they work very quickly, but as i mentioned before, in reports they take up to 10 minutes to load (for approximately 200 employees) and using them in a query for the report takes longer and causes the report to recalculate whenever i scroll through it.
I'm not sure how to be more specific, I think im really looking for some kind of best practice suggestion when using multiple (around 15) functions (that call on eachother) in a query/report