I have a similar problem and being very new to access and not a VB programmer, am wondering how/where you would install code of this type. Can it be in a querie or does it go into a form or report?
Code was copied from another thread titled “Complex if” started by MTN, I have no problem understanding the code just don’t know how to use it in Access.
Code would be changed to involve a graduated scale for wages vs hours worked. Thought about an IIF in a Quierie but would be about 6 ifs deep, plus don't want to leave it for somebody in the future to have to understand.
Thanks in advance folks.
Dim dEarning As Double
Dim dPaye As Double
dEarning = Nz(Me.txtEarning, 0)
dPaye = 0
'is there anything in earnings?
If dEarning > 0 Then
'assign first 30000 @ 5% (if less than compute)
If dEarning >= 30000 Then
dPaye = 1500
Else
dPaye = dPaye + (dEarning * 0.05)
End If
dEarning = dEarning - 30000
'anything left in earnings?
If dEarning > 0 Then
'assign second 30000 @ 10%
If dEarning >= 30000 Then
dPaye = 4500
Else
dPaye = dPaye + (dEarning * 0.1)
End If
dEarning = dEarning - 30000
'anything left in earnings?
If dEarning > 0 Then
'assign third 50000 @ 15%
If dEarning >= 50000 Then
dPaye = 12000
Else
dPaye = dPaye + (dEarning * 0.15)
End If
dEarning = dEarning - 50000
'anything left in earnings?
If dEarning > 0 Then
'assign fourth 50000 @ 15%
If dEarning >= 50000 Then
dPaye = 22000
Else
dPaye = dPaye + (dEarning * 0.2)
End If
dEarning = dEarning - 50000
'anything left in earnings?
If dEarning > 0 Then
'assign remainder @ 25%
dPaye = dPaye + (dEarning * 0.25)
End If
End If
End If
End If
End If
'populate the control with PAYE calculation
Me.txtPAYE = dPaye
Code was copied from another thread titled “Complex if” started by MTN, I have no problem understanding the code just don’t know how to use it in Access.
Code would be changed to involve a graduated scale for wages vs hours worked. Thought about an IIF in a Quierie but would be about 6 ifs deep, plus don't want to leave it for somebody in the future to have to understand.
Thanks in advance folks.
Dim dEarning As Double
Dim dPaye As Double
dEarning = Nz(Me.txtEarning, 0)
dPaye = 0
'is there anything in earnings?
If dEarning > 0 Then
'assign first 30000 @ 5% (if less than compute)
If dEarning >= 30000 Then
dPaye = 1500
Else
dPaye = dPaye + (dEarning * 0.05)
End If
dEarning = dEarning - 30000
'anything left in earnings?
If dEarning > 0 Then
'assign second 30000 @ 10%
If dEarning >= 30000 Then
dPaye = 4500
Else
dPaye = dPaye + (dEarning * 0.1)
End If
dEarning = dEarning - 30000
'anything left in earnings?
If dEarning > 0 Then
'assign third 50000 @ 15%
If dEarning >= 50000 Then
dPaye = 12000
Else
dPaye = dPaye + (dEarning * 0.15)
End If
dEarning = dEarning - 50000
'anything left in earnings?
If dEarning > 0 Then
'assign fourth 50000 @ 15%
If dEarning >= 50000 Then
dPaye = 22000
Else
dPaye = dPaye + (dEarning * 0.2)
End If
dEarning = dEarning - 50000
'anything left in earnings?
If dEarning > 0 Then
'assign remainder @ 25%
dPaye = dPaye + (dEarning * 0.25)
End If
End If
End If
End If
End If
'populate the control with PAYE calculation
Me.txtPAYE = dPaye