View Full Version : Clearing a Query using VBA


jaxxstorm
03-14-2007, 07:24 AM
Earlier in the week, I was given this useful code to automate a cost calucation field in my form

Forms!MakeOrders!CostOfOrder = DSum("[OrderAmount]", "qryCostCalculation", "[OrderNo] = " & Forms!MakeOrders!OrderNo)

taking the value from a query which calculated the orderamount.

However, I've now noticed it is adding up all the orderamounts for each order in the query, including previous orders.

Is there a way of JUST taking one line of the order amount query? Possibly clearing the query after it's used so the order amount is not incremental?

Any help much appreciated

llkhoutx
03-14-2007, 07:31 AM
Shouldn't you be using DLookup rather than DSUM?

jaxxstorm
03-14-2007, 07:40 AM
That wouldn't work, as the value being calculated is in the current form, so hasn't been stored as of yet..

Rich
03-14-2007, 07:55 AM
If it's already on the form why do you need to look it up?