loop thru records

skate

Registered User.
Local time
Today, 13:37
Joined
May 22, 2002
Messages
136
How do I loop through records in a subform to add the values of a certain field to be displayed in a single field in another subform? I am not a programmer, so any helpful details of the code would be greatly appreciated
 
If you are trying to get a total of numeric values in a field then you can use code like this in the Control Source of an unbound control in the forms footer to get the total for the records displayed:

=Sum([NameOfFieldToTotal])

You can then refer to this control on the form or in another subform on the same form. This
article will show you how to refer to controls on forms and subforms.

hth,
Jack
 
it didn't reconize that function.

this is the code I am using
Dim JTotal As Double
Dim rst As Recordset
JTotal = 0
Set rst = Forms!Day![Day subform].Form.Recordset
Do While Not rst.EOF
JTotal = JTotal + Forms!Day![Day subform].Ctl1
rst.MoveNext
Loop
Text20 = JTotal

but I'm not sure if it is appropriate to use EOF since it is a filtered list in the subform
 
Try the Sum() function that I outlined above. If you have a field called MyTotal in your subform that has a value in it then:

=Sum([MyTotal])

in an unbound control in the form's footer will return a total of all the records shown in your subform. You do not need the code you are using. You can try this by opening your subform directly and you will see the total of all of the MyTotal fields.

Jack
 

Users who are viewing this thread

Back
Top Bottom