prabha_friend
Prabhakaran Karuppaih
- Local time
- Today, 07:08
- Joined
- Mar 22, 2009
- Messages
- 881
Rich (BB code):
Private Sub Form_AfterInsert()
Dim CurrentTransDate As Date
CurrentTransDate = Me.DateVal.Value
Dim Transet As Recordset
Set Transet = CurrentDb.OpenRecordset("SELECT Amount FROM Transactions where To=" & Me.To.Value & " AND Head=" & Me.Head.Value & " AND DateVal<#" & Format(CurrentTransDate, "mm/dd/yyyy hh:mm:ss") & "#;")
'Basic Pay
Dim BasicPay As Currency
With Transet
If .EOF = True Then
BasicPay = 100000
Me.DateVal.Value = Format(#1/1/2020#, "mm/dd/yyyy hh:mm:ss")
Else
.MoveLast
BasicPay = Transet.Fields("Amount").Value
End If
End With
Me.Amount.Value = BasicPay
'Hikes
Dim HikeStatus As Boolean
HikeStatus = IIf(DCount("ID", "Hikes", "Effective_Date<#" & CurrentTransDate & "#") > 0, False, True)
If Not HikeStatus = True Then
Dim Hikeset As Recordset
Set Hikeset = CurrentDb.OpenRecordset("SELECT Percentage, Status, Effective_Date FROM Hikes where Staff=" & Me.To.Value & " AND Record_Date<=#" & Format(CurrentTransDate, "mm/dd/yyyy hh:mm:ss") & "# AND Status = FALSE" & ";")
With Hikeset
If Not .EOF = True Then
.MoveLast
BasicPay = BasicPay + (BasicPay * .Fields("Percentage").Value)
'Arrears
Dim ArrearStatus As Boolean
ArrearStatus = IIf(DCount("ID", "Transactions", "To=" & Me.To.Value & " AND DateVal<#" & CurrentTransDate & "# AND Head=30") > 0, True, False)
If ArrearStatus = False Then
CurrentDb.Execute ("INSER-T INTO Transactions (To,Head,Amount) VALUES (" & Me.To.Value & "," & 30 & "," & (BasicPay + (BasicPay * Hikeset.Fields("Percentage").Value)) * (DateDiff("m", Hikeset.Fields("Effective_Date"), CurrentTransDate)) & ");")
Me.Requery
With Hikeset
.Edit
.Fields("Status").Value = True
.Update
End With
End If
End If
End With
End If
Me.Amount.Value = BasicPay
DoCmd.Save
Me.Requery
End Sub