ClaraBarton
Registered User.
- Local time
- Today, 15:27
- Joined
- Oct 14, 2019
- Messages
- 645
Code:
Public Function FldCalc(frm As Form, ctrl As Control)
On Error Resume Next
Select Case ctrl.Name
Case "txtPayment"
If Left(frm.ctrl, 1) = "=" Then frm.ctrl = Right(frm.ctrl, Len(frm.ctrl) - 1)
frm.Payment = 0
frm.Payment = Eval(frm.ctrl)
frm.ctrl = frm.Payment
RetAmt frm, txtPayment
Case "txtReceipt"
If Left(frm.ctrl, 1) = "=" Then frm.ctrl = Right(frm.ctrl, Len(frm.ctrl) - 1)
frm.Payment = 0
frm.Payment = Eval(frm.ctrl)
frm.ctrl = frm.Receipt
RetAmt frm, "txtReceipt"
End Select
End Function
'Payment and Receipt in AfterUpdate Event
Public Function RetAmt(frm As Form, tbx As Control)
Select Case tbx.Name
Case txtPayment
frm.Receipt = Null
frm.txtReceipt = Null
frm.Amount = -tbx.Value
Case "txtReceipt"
frm.Payment = Null
frm.txtPayment = Null
frm.Amount = tbx.Value
End Select
End Function
The variable for control will not compile.
RetAmt frm, txtPayment returns "variable not defined" .
All forms and subforms have the same textboxes with the same names so this seemed like the way to go. The first function does the calculating and the second one puts the results in the right field.
I guess if the controls have the same name, I wouldn't have to use a variable...