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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum Controls. 1

Status
Not open for further replies.

lars7

Technical User
Aug 16, 2005
817
GB
Hi Guys,
I want to sum all the controls in my subForm but if there is a 0 then it won't show anything. Here is the code I am using in an unbound text box:

=Sum([HerSun])+Sum([DailyRec])+Sum([Met])+Sum([WoM])+Sum([JobCen])+Sum([VacBul])+Sum([Jou])+Sum([JouWeb])+Sum([NHSInt])+Sum([OpDa])+Sum([RefBy])+Sum([Sh])+Sum([Cam])

I have this in the bound controls:

=IIf([HerSun] Is Null,0,[HerSun])

Can anyone see where I am going wrong.
 
How are ya lars7 . . .

Add a question mark [purple]?[/purple] to the [blue]Tag[/blue] property of all the controls involved in the sum. Next copy/paste the following function to the code module of the form.
Code:
[blue]Public Function AllSum()
   Dim ctl As Control, hldSum
   
   For Each ctl In Me.Controls
      If ctl.Tag = "?" Then
         hldSum = hldSum + Nz(ctl)
      End If
   Next
   
   AllSum = hldSum

End Function[/blue]
The change you formula to
Code:
[blue] = AllSum()[/blue]

Calvin.gif
See Ya! . . . . . .
 
I think you will need some Nz in your sum statement. This may interest you:
Count checked Check Boxes on a report
thread705-361544
 
Thanks guys for the replys

I tried yours and it works great.
 
Hi,
I have tried to install the same code in a report and I am getting an error message saying "error in loading DLL" am I missing a reference in the library:

Public Function AllSum()
Dim ctl As Control, hldSum

For Each ctl In Me.Controls
If ctl.Tag = "?" Then
hldSum = hldSum + Nz(ctl)
End If
Next

AllSum = hldSum

End Function

 
Sorry guys false alarm, it had something to do with me logging in to another computer that didn't have office 2003 (I think). It's fine now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top