I hope you can help me. I am using MS access 2003 and have created a table with folloing fields
RefNo,TransactionDate,Detail,Debit,Credit and balance. Transaction dates are indexed in table. I have created a form where i enter the date and amount in either debit or credit field and it will calculate the balance. My problem is it is fine if done in sequential order but if i need to enter one missing transaction in the middle for old date it needs to look at the last balance for that date and add or substract accorting to the credit or debit amount and should also adjust the subsequent balance.Can anyone help me to write the code? Thank you in advance.
I hope you can help me. I am using MS access 2003 and have
Share
This is what I came up with. It requires a non unique composite index of
RefNo, TransactionDate, Debit and Credit (all Ascending) on your table (referred to as Transactions in my example)
Sample data looks like this
VBA code
Call this routine when you save a new transaction record supplying Refno and Transaction date and it will recalculate the daily balances from the most recent date prior to the current transaction date onwards. If no previous balance can be found a zero balance is created based on the current transaction date minus 1 day.
Additional:
The VBA code should be pasted into a seperate module i.e. not in the form code behind.
On your form you should have a save button. You need to add some code to the button’s On Click event to save the record and then run the CalculateBalance code. Here’s an example
Note that when you add command buttons and use the wizard to configure the button action Access creates a Macro rather than inserting code behind the form. You will need to change the button’s On Click property from
[Embedded Macro]to[Event Procedure].Hope this helps