Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access: Running Average

Status
Not open for further replies.

maerts

Technical User
Oct 24, 2002
20
0
0
US
How do you create a running average in an unbound field in a form. For example, line 1 will just be an average of itself. Line 2 will be an average of line 1 and 2, line 3 will be an average of line 1, 2, and 3... and so on.
 
More info is needed.
What are you calculating the average of?
(You can't calculate the average of an unbound textbox, as by definition it would always be the current visible value)
 
(I am sorry..I am not a technical user...I am using my husband's account) I have a subform that has a Price column and the next column I want to have a running average of the Price column.
 
To do this you must have a unique id for each record in the subform (not necessarily unique across all records in the table) and the records must be listed in that sequence (ascending or descending).

The subform must be based on a query. It is necessary to add an extra column to the query to represent the running average.
The extra column would look something like:

MyAvg:Davg("[Pricefield]", "mytable", "mytable.mylinkfield = & mylinkfield & " AND mytable.uniqueidfield <= " & uniqueidfield)

Some syntax changes may be required if any of the fields are text rather than numbers.

Then you use this extra field in the query as the source for what is currently your Unbound textbox.
 
I am assuming that mylinkfield is the field that links the form and the subform to each other...which is a text field not numbers. How do I adjust the syntax for this?
 
MyAvg:Davg("[Pricefield]", "mytable", "mytable.mylinkfield = '" & mylinkfield & "' AND mytable.uniqueidfield <= " & uniqueidfield

There was a double quote missing in my last post.
Single quotes have also been added to deal with the text value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top