How to get the sum of a field

  • Thread starter Thread starter Toxin
  • Start date Start date
T

Toxin

Guest
I have a field called sales, and I know that you need to place an expression in the control source property but I'm not really sure what the expression is.

Alsowhat object and property can be used to refer to the form that is currently active.

Thanks for any help! :)
 
Last edited:
Place the sum function in the control source of the field:

= Sum([sales])

You can refer to the currently Activeform in your code as Me if the code is part of the form's class module:

ie. Me!sales refers to the sales field of the current form
 
The other way to do this is, for GENERAL modules (not CLASS modules), you can look at the ActiveForm property of the Screen object. (Screen object is one of those 'default' objects.)

The problem is, if the code happens to be running in the background because of a timer, the activeform reference might trap an error. Also, if used from code called through a sub-form, the parent form is considered the ActiveForm.

Where it makes sense (forms and reports), "Me" is preferred in class modules. You can also use Me as an argument to your general modules if they are set up to expect an object or an object name.
 

Users who are viewing this thread

Back
Top Bottom