Function as a query field?

lution

Registered User.
Local time
Today, 06:58
Joined
Mar 21, 2007
Messages
114
I've inherited a database that used to have a total field in it. I've removed the total but now find myself having to recalculate the total from existing fields in 37 places including 22 queries. Is there any way to create a function that can access the fields in the current records and return the total?

if this was on a form I could do something like:
Code:
public function curGetTotal() as currency

  curGetTotal = me.curCost + me.curPenalty + me.curForfeiture

end function

But calling this from a query says it doesn't recognize me.

Thanks
 
If the values will always be in that form and the form will be open:

curGetTotal = Forms!FormName.curCost + Forms!FormName.curPenalty + Forms!FormName.curForfeiture

Otherwise, you'd probably need to change the function so it accepted the values as parameters.
 
but if I wanted to use the function as part of a query so the query returned the total as one if it's properties?
 
Presuming the form isn't available, you'd need to modify the function to accept parameters:

public function curGetTotal(Value1 as currency, Value2 as currency) as currency

And pass the parameters when you call it:

NewField: curGetTotal(Field1, Field2)
 

Users who are viewing this thread

Back
Top Bottom