Gasman
Enthusiastic Amateur
- Local time
- Today, 17:23
- Joined
- Sep 21, 2011
- Messages
- 17,060
Hi everyone,
I have a form that holds amount for a record and I used to enter the balance as calculated from an Excel sheet I also maintain.
This form was really just to create emails to advise caseworkers and my boss.
However I have now amended the amounts to be negative or positive depending on the transaction type and want the form to calculate the balance automatically. The Balance is stored in the record as well.
The following code works great when adding a record, but if I have a need to go back and edit the amount, the balance is not changed on the form after I leave the Amount control.?
I've tried a Me.Refresh and Me.Balance.Requery which did not work.
I added Me.Dirty test to the Me.NewRecord test as I believe it is because the record has not been saved and Dsum does not pick the new amount up.?
What do I need to add to be able to just modify amount and immediately see the correct value in the Balance field please?
TIA
I have a form that holds amount for a record and I used to enter the balance as calculated from an Excel sheet I also maintain.
This form was really just to create emails to advise caseworkers and my boss.
However I have now amended the amounts to be negative or positive depending on the transaction type and want the form to calculate the balance automatically. The Balance is stored in the record as well.
The following code works great when adding a record, but if I have a need to go back and edit the amount, the balance is not changed on the form after I leave the Amount control.?
Code:
Private Sub Amount_LostFocus()
If Me.TranType = "Payment" And Me.Amount > 0 Then
Me.Amount = Me.Amount * -1
End If
Me.Balance = DSum("[Amount]", "Emails", "[CMS]=" & Me.CMS)
If Me.NewRecord Then
Me.Balance = Me.Balance + Me.Amount
End If
End Sub
I've tried a Me.Refresh and Me.Balance.Requery which did not work.
I added Me.Dirty test to the Me.NewRecord test as I believe it is because the record has not been saved and Dsum does not pick the new amount up.?
What do I need to add to be able to just modify amount and immediately see the correct value in the Balance field please?
TIA