By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,478 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,478 IT Pros & Developers. It's quick & easy.

Help! Need to calculate and store value based on total in Subform

P: 11
I am trying to create an invoice program that will automatically generate an invoice based on charges entered in a subform. Sounds easy enough!

I have created my Total field on subform as unbound and called it Ttl. I have used this code to tally the total of all charges =Sum([Charge]). This works fine. I have then put a GrandTotal filed on my Customer info form and asigned it this value =frmCharges.Form!Ttl. Again, the field total looks fine as long as I only enter one charge. Problem is I there will be multiple charges for most invoices!
I have entered the recalc code in the OnChange but still nothing.

What am I doing wrong here!!
Jan 31 '08 #1
Share this Question
Share on Google+
3 Replies


puppydogbuddy
Expert 100+
P: 1,923
I am trying to create an invoice program that will automatically generate an invoice based on charges entered in a subform. Sounds easy enough!

I have created my Total field on subform as unbound and called it Ttl. I have used this code to tally the total of all charges =Sum([Charge]). This works fine. I have then put a GrandTotal filed on my Customer info form and asigned it this value =frmCharges.Form!Ttl. Again, the field total looks fine as long as I only enter one charge. Problem is I there will be multiple charges for most invoices!
I have entered the recalc code in the OnChange but still nothing.

What am I doing wrong here!!
ezra,
The OnChange event does not fire for calculations or updates via code. It fires only for changes due to data input. Try to move the recalc code to the Form_BeforeUpdate() event for the subform, and see if that helps.
Feb 1 '08 #2

P: 11
ezra,
The OnChange event does not fire for calculations or updates via code. It fires only for changes due to data input. Try to move the recalc code to the Form_BeforeUpdate() event for the subform, and see if that helps.
Thanks

The form field does calculate properly now but the correct total doesn't stored in the Total field in the underlying table.
Feb 1 '08 #3

puppydogbuddy
Expert 100+
P: 1,923
Thanks

The form field does calculate properly now but the correct total doesn't stored in the Total field in the underlying table.

ezra,
as a general rule calculations are not stored in the table because they can derived any time from the stored components any time it is needed. However, if you want to store it irregardless, you can. Add the following line to the Form_AfterUpdate() event of your subform, assuming that the subform record source is the table that has the total field.

YourFieldName = Me!YourControlName
Feb 1 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.