Calculating totals across a main form and subforms

Calculating totals across a main form and subforms

Hi,
I would like to be able to access items on a Form and its Subforms from within  separate  Function  before the Form is saved  

I cannot work out how to access the current new record Form Fields and Sub From Fields from a separate Function before the Form data is saved. 

Could you provide me with some sample code which shows how to do this?

More detail:

I am trying to to access data as it is entered into a Form from within a separate  Function to avoid duplicating code across a series 'on user input' and 'on update' areas.

Example:
I have a application which allows users to add 5 different families of products to an Order Form. I have achieved this by creating a Subform for the user to select the required products from each product family. This allows the user to pick 3 products from Family A, 4 products from Family B etc and these get combined into the one order. This all works very well :)

I have been able to calculate the order Total in deluge code by iterating through the different fields and Subformson the Booking Form before it is submitted. This all works very well too.

My problem is working out how to relocate this 'Calculate Total' Code to a separate Function to avoid duplicating code numerous times.