DSum

Chrisopia

Registered User.
Local time
Today, 08:12
Joined
Jul 18, 2008
Messages
279
What is the best property to add DSum to a control to?

By that I mean, I need to add fields up as theyre being entered.

I have this so far:

Code:
Private Sub Price[B][COLOR=Blue]_BeforeUpdate(Cancel As Integer)[/COLOR][/B]

Dim Loc As String
Dim Calc As String
Loc = Me![Wizard step 2 subform order details].Form![DescriptionID]
Calc = DSum("[Price]", "[tblOrderDetails]", "[DescriptionID]=" & Loc)
End Sub

Calc will find the field Price from the table tblOrderDetails where the DescriptionID match... then add them up... simple... its jsut the enttries from tblOrderDetails are still to be entered.

I know Before update doesnt work, but I've tried afterupdate as well but nothing else on the list seemed to be what I was after?
 
When are you wanting to calculate the values, when the form upadates or when the subform is updated?
 
as I'm typing...

theres OnChange which i just discovered and am trying to figure out
 
yeah the problem Change has is it's delayed :S... like if I entered 10, Price would still be 0
When I entered 15 in the next field it would change to 10
and when I entered 5 in the next one it would change to 25!?
 
and now I get the problem "Invalid Use of Null" for descriptionID
 
Let's back up for a second...

You have a form 'orders' and a sub form for 'details'. What is it you're wanting to total? A price value in the order details?
 
The orderDetails is where the price is entered... they are totaled on the form Description.

Description contains the subform orderDetails
 
I would put a footer in the subform and put a text box there and do something like:

=sum(myFieldaName)
 
As an FYI, while this situation doesn't sound appropriate for the Change event to me, to use it you have to refer to the Text property of the control. The default Value property is not updated at that point.
 
Hi kenn, thanks for the suggestion but I did try that a long time ago but ran into problems, where I worked everything out in the form in the control... unfortunately I was told it wasn't very good at working out sums (which explained why it didnt work when I first tried it) and was told its better to work things out in a query before hand...
 
I think whoever gave you that advice may have meant to build a query that sums the totals in your details table by order number then add/link that to your forms query....

Make sense?
 

Users who are viewing this thread

Back
Top Bottom