Payment Form
I was to have a database that will track individual payments of a due payment (i.e. Customer pays a bit one day, and still has more remaining for another day, etc) . I have a "customer" table, a "Payments" table and a "CustomerPay" table (that links the 2).
The Structures of the tables are as follows:
Customer
MembershipNo (PK) , Name, etc
Payment
PaymentNo (PK) , prevBalance, paidAmt, datePaid, balanceForward, etc
CustomerPay
MembershipNo (PK) , PaymentNo (PK)
I have tried to implement the following code on form load. Has anyone seen any examples of have any ideas that would help. How do I check if a record exists with a specific criteria? I would be much appreciative.
Btw, the SQL code of the query used on my payment form is as follows . . . . .
(if that helps any
)
Thanks
I was to have a database that will track individual payments of a due payment (i.e. Customer pays a bit one day, and still has more remaining for another day, etc) . I have a "customer" table, a "Payments" table and a "CustomerPay" table (that links the 2).
The Structures of the tables are as follows:
Customer
MembershipNo (PK) , Name, etc
Payment
PaymentNo (PK) , prevBalance, paidAmt, datePaid, balanceForward, etc
CustomerPay
MembershipNo (PK) , PaymentNo (PK)
I have tried to implement the following code on form load. Has anyone seen any examples of have any ideas that would help. How do I check if a record exists with a specific criteria? I would be much appreciative.
Code:
'On Error GoTo 1
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim SQL_prev As String
Dim SQL_curr As String
Set dbs = CurrentDb
Dim prevPayNo As Integer
SQL_curr = "SELECT * " & _
"FROM Payment " & _
"WHERE (PaymentNo = " & paymentNo & ")"
Set rst1 = dbs.OpenRecordset(SQL_curr)
prevPayNo = rst1!paymentNo.Value - 1
If (prevPayNo > 0) Then
SQL_prev = "SELECT * " & _
"FROM Payment " & _
"WHERE (PaymentNo = " & prevPayNo & ")"
Set rst2 = dbs.OpenRecordset(SQL_prev)
If (rst1!prevBalance > 0) And (rst2!paymentNo <> Null) Then
rst1.Edit
rst1!prevBalance = rst2!forwardBalance
prevBalance = rst2!forwardBalance
rst1!forwardBalance = rst1!prevBalance - paidAmt
forwardBalance = rst1!prevBalance - paidAmt
rst1.Update
End If
Else
prevBalance = price
End If
'1:
Btw, the SQL code of the query used on my payment form is as follows . . . . .
Code:
SELECT CustomerPay.membershipNo, CustomerPay.paymentNo, Customer.firstName, Customer.lastName, MemberTypes.memberType, Payment.typeNo, Payment.prevBalance, Payment.paidAmt, Payment.datePaid, Payment.forwardBalance, Customer.dateJoined, MemberTypes.price, Payment.passesRemaining, DateAdd("m",[memberTypeLength],[dateJoined]) AS dateExpiry
FROM (MemberTypes INNER JOIN Payment ON MemberTypes.typeNo = Payment.typeNo) INNER JOIN (Customer INNER JOIN CustomerPay ON Customer.membershipNo = CustomerPay.membershipNo) ON Payment.paymentNo = CustomerPay.paymentNo;
Thanks
Last edited: