G
Guest
Hi there,
I have a query "salary total"(2 tables) , I would like to create a function
to calculate the salary but it does not work, code as follows. Appreciate for
your expert help!
Function dailysalary()
Dim mysalary As Single
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("salary total")
Set rst = qdf.OpenRecordset
Do
If rst![work details]![START TIME] > 8 And rst![work details]![START TIME] <
13 And rst![work details]![END TIME] > 13 And rst![work details]![END TIME] <
19 Then
mysalary = (13 - rst![work details]![START TIME] + rst![work details]![END
TIME] - 14) * rst![work details]![SALARY] / 8
ElseIf rst![work details]![START TIME] > 8 And rst![work details]![END TIME]
< 14 Then
mysalary = (rst![work details]![END TIME] - rst![work details]![START TIME])
* rst![work details]![SALARY] / 8
ElseIf rst![work details]![START TIME] > 13 And rst![work details]![END
TIME] < 19 Then
mysalary = (rst![work details]![END TIME] - rst![work details]![START TIME])
* rst![work details]![SALARY] / 8
ElseIf rst![work details]![START TIME] > 8 And rst![work details]![START
TIME] < 13 And rst![work details]![END TIME] > 13 And rst![work details]![END
TIME] > 19 And rst![work details]![END TIME] <= 24 Then
mysalary = (13 - rst![work details]![START TIME] + 18 - 14) * rst![work
details]![SALARY] / 8 + (rst![work details]![END TIME] - 18) * rst![work
details]![SALARY] / 8 * 1.5
ElseIf rst![work details]![START TIME] > 8 And rst![work details]![START
TIME] < 13 And rst![work details]![END TIME] > 13 And rst![work details]![END
TIME] > 19 And rst![work details]![END TIME] > 24 Then
mysalary = (13 - rst![work details]![START TIME] + 18 - 14) * rst![work
details]![SALARY] / 8 + (24 - 18) * rst![work details]![SALARY] / 8 * 1.5 +
(rst![work details]![END TIME] - 24) * rst![work details]![SALARY] / 8 * 2
ElseIf rst![work details]![START TIME] > 13 And rst![work details]![END
TIME] > 18 And rst![work details]![END TIME] <= 24 Then
mysalary = (18 - rst![work details]![START TIME]) * rst![work
details]![SALARY] / 8 + (rst![work details]![END TIME] - 18) * rst![work
details]![SALARY] / 8 * 1.5
ElseIf rst![work details]![START TIME] > 13 And rst![work details]![END
TIME] > 18 And rst![work details]![END TIME] > 24 Then
mysalary = (18 - rst![work details]![START TIME]) * rst![work
details]![SALARY] / 8 + (24 - 18) * rst![work details]![SALARY] / 8 * 1.5 +
(rst![work details]![END TIME] - 24) * rst![work details]![SALARY] / 8 * 2
Else
mysalary = 0
End If
rst.MoveNext
Loop Until rst.EOF
dailysalary = mysalary
End Function
I have a query "salary total"(2 tables) , I would like to create a function
to calculate the salary but it does not work, code as follows. Appreciate for
your expert help!
Function dailysalary()
Dim mysalary As Single
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("salary total")
Set rst = qdf.OpenRecordset
Do
If rst![work details]![START TIME] > 8 And rst![work details]![START TIME] <
13 And rst![work details]![END TIME] > 13 And rst![work details]![END TIME] <
19 Then
mysalary = (13 - rst![work details]![START TIME] + rst![work details]![END
TIME] - 14) * rst![work details]![SALARY] / 8
ElseIf rst![work details]![START TIME] > 8 And rst![work details]![END TIME]
< 14 Then
mysalary = (rst![work details]![END TIME] - rst![work details]![START TIME])
* rst![work details]![SALARY] / 8
ElseIf rst![work details]![START TIME] > 13 And rst![work details]![END
TIME] < 19 Then
mysalary = (rst![work details]![END TIME] - rst![work details]![START TIME])
* rst![work details]![SALARY] / 8
ElseIf rst![work details]![START TIME] > 8 And rst![work details]![START
TIME] < 13 And rst![work details]![END TIME] > 13 And rst![work details]![END
TIME] > 19 And rst![work details]![END TIME] <= 24 Then
mysalary = (13 - rst![work details]![START TIME] + 18 - 14) * rst![work
details]![SALARY] / 8 + (rst![work details]![END TIME] - 18) * rst![work
details]![SALARY] / 8 * 1.5
ElseIf rst![work details]![START TIME] > 8 And rst![work details]![START
TIME] < 13 And rst![work details]![END TIME] > 13 And rst![work details]![END
TIME] > 19 And rst![work details]![END TIME] > 24 Then
mysalary = (13 - rst![work details]![START TIME] + 18 - 14) * rst![work
details]![SALARY] / 8 + (24 - 18) * rst![work details]![SALARY] / 8 * 1.5 +
(rst![work details]![END TIME] - 24) * rst![work details]![SALARY] / 8 * 2
ElseIf rst![work details]![START TIME] > 13 And rst![work details]![END
TIME] > 18 And rst![work details]![END TIME] <= 24 Then
mysalary = (18 - rst![work details]![START TIME]) * rst![work
details]![SALARY] / 8 + (rst![work details]![END TIME] - 18) * rst![work
details]![SALARY] / 8 * 1.5
ElseIf rst![work details]![START TIME] > 13 And rst![work details]![END
TIME] > 18 And rst![work details]![END TIME] > 24 Then
mysalary = (18 - rst![work details]![START TIME]) * rst![work
details]![SALARY] / 8 + (24 - 18) * rst![work details]![SALARY] / 8 * 1.5 +
(rst![work details]![END TIME] - 24) * rst![work details]![SALARY] / 8 * 2
Else
mysalary = 0
End If
rst.MoveNext
Loop Until rst.EOF
dailysalary = mysalary
End Function