getting total of a repeated field

# Thread: getting total of a repeated field

1. Senior Member
Join Date
Dec 1969
Posts
339

## getting total of a repeated field

&nbsp;<BR>i was thinking of getting the total of repeated fields. how can it be done?<BR>i am inside loop, and here is my code:<BR><BR>allhrs = total_hours<BR>allRS3.MoveNext<BR>allhrs = allhrs + total_hours<BR><BR>is this correct, or what?<BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## RE: getting total of a repeated field

Think *CLOSELY* about what you wrote:<BR><BR>&#060;%<BR>&#039; You didn&#039;t write the next line, but you must have something like it:<BR>Do Until allRS3.EOF<BR>&nbsp; &nbsp; ...<BR>&nbsp; &nbsp; &#039; And you must have something similar to this line:<BR>&nbsp; &nbsp; total_hours = allRS3("total_hours") <BR>&nbsp; &nbsp; ...<BR>&nbsp; &nbsp; allhrs = total_hours &#039; ### LINE A<BR>&nbsp; &nbsp; allRS3.MoveNext<BR>&nbsp; &nbsp; allhrs = allhrs + total_hours &#039; ### LINE B<BR>&#039; and this line must exist, too:<BR>Loop<BR>%&#062;<BR><BR>Now, let&#039;s say that you start off with allhrs = 0 to begin with.<BR><BR>And the first time through the loop, let&#039;s say you find the value 36 in that allRS3("total_hours") [or wherever it comes from], so now total_hours is 36.<BR><BR>Now, on LINE A, you assign allhrs = total_hours. So allhrs is now 36, too, right?<BR><BR>And then you get to LINE B and do allhrs = allhrs + total_hours, so 36 + 36 is 72 and now allhrs has the value 72.<BR><BR>On the *second* time through the loop, let&#039;s say you find the value 17 in that allRS3("total_hours") [or wherever it comes from], so now total_hours is 17.<BR><BR>Now, on LINE A, you assign allhrs = total_hours. So allhrs is now 17, too, right? Ummm...ummmm...what happened to the 72 that you had there before??? Hey, it&#039;s all gone! You just asked to replace the entire contents of allhrs with the entire contents of total_hours. You didn&#039;t say anything at all about retaining the prior value!<BR><BR>And then you get to LINE B and do allhrs = allhrs + total_hours, so 17 + 17 is 34 and now allhrs has the value 34.<BR><BR>***************<BR><BR>Somehow, I doubt seriously that this is what you are after.<BR><BR>May I presume and hope that you can fix this yourself?<BR><BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•