Professional Documents
Culture Documents
Dim STRSQL As String
Dim STRSQL As String
' Get the selected pay date, staff name, and loan paid off date from the form
payDate = Me.PaidDate.Value
EmpCode = Me.EmpCode.Value
' Retrieve the loan paid off date from the tblLoan2 table
strSQL = "SELECT LoanPaidOffDate FROM tblLoan2 WHERE EmpCode = '" & EmpCode & "'"
loanStartDate = DLookup("LoanStartDate", "tblLoan2", "EmpCode = '" & EmpCode & "'")
LoanPaidOffDate = DLookup("LoanPaidOffDate", "tblLoan2", "EmpCode = '" & EmpCode & "'")
' Check if the loan start date is earlier than or equal to the pay date and the pay date is earlier
than or equal to the loan paid off date
If Not IsNull(loanStartDate) And Not IsNull(LoanPaidOffDate) And payDate >= loanStartDate And
payDate <= LoanPaidOffDate Then
' Retrieve the loan amount from the tblLoan2 table
strSQL = "SELECT LoanAmt FROM tblLoan2 WHERE EmpCode = '" & EmpCode & "'"
LoanAmt = CDbl(DLookup("LoanAmt", "tblLoan2", "EmpCode = '" & EmpCode & "'"))
Else
' Set the loan amount to zero if the loan is not within the valid period or no loan record is found
LoanAmt = 0
End If
' Set the PLoan field in the Payroll 2 form to the calculated loan amount
Forms("Form2").PLoan.Value = LoanAmt
Private Sub UpdateLoanAmount()
' Existing code for retrieving loan information