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

sum my records 1

Status
Not open for further replies.

CompGirl

Technical User
Jun 2, 2003
40
SE
hello everyone

this is the code behind my report, the only thing that i want to do is to sum the IDs that pop up ..

Private bContinuedSection As Boolean, sLastHeaderKey As Variant
Private Function IsContinuedSection() As Boolean
IsContinuedSection = bContinuedSection
End Function

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim Re As DAO.Recordset
Dim Envi_Risk_Class, Risk
Set Re = CurrentDb.OpenRecordset("SELECT Envi_Risk_Class, HazardID FROM tblHazard Where Envi_Risk_Class ='" & Me!hiddenEnvi_Risk_Class & "' ORDER BY HazardID")
Risk = ""
Me!Risker = Me!hiddenEnvi_Risk_Class
Do While Not Re.EOF
Risk = Risk & Re!HazardID & ", "
Re.MoveNext
Loop
Me!ID = Left(Risk, Len(Risk) - 2)
End Sub

can someone give me an idea? thx

 
you could requery with an SQL SUM rather than doing a loop
i.e.

Set Re = CurrentDb.OpenRecordset("SELECT SUM(HazardID) as HazardTotal FROM tblHazard Where Envi_Risk_Class ='" & Me!hiddenEnvi_Risk_Class & "')

total = Re("HazardTotal")



'mi casa es su casa'
]-=tty0=-[
 
but i want to keep the ids.. and just add another box that prints out total...? how am i supposed to do then
 
ok to keep it all seperate if there is a text box called txtSumTotal you could put this in the sub, so you dont use the same recordset:

Dim ReSum As DAO.Recordset

Set ReSum = CurrentDb.OpenRecordset("SELECT SUM(HazardID) as HazardTotal FROM tblHazard Where Envi_Risk_Class ='" & Me!hiddenEnvi_Risk_Class & "')

txtSumTotal.text = ReSum("HazardTotal")

'mi casa es su casa'
]-=tty0=-[
 
hmmm it seems right but its complaining on that.. it wont work :/
 
i dont understand where the compiling error is
 
what error is it giving you?

'mi casa es su casa'
]-=tty0=-[
 
list seperator or )

either im stupid or blinde
 
thx.. it was nothing.. like i said i was blinde ;) thx for ya time
 
Where is the break? is it on the text box line?

ReSum("HazardTotal")

if so try this instead

ReSum!HazardTotal



'mi casa es su casa'
]-=tty0=-[
 
Set Re = CurrentDb.OpenRecordset("SELECT Envi_Risk_Class, HazardID FROM tblHazard Where Envi_Risk_Class ='" & Me!hiddenEnvi_Risk_Class & "' ORDER BY HazardID")
Risk = ""
Me!Risker = Me!hiddenEnvi_Risk_Class
tot=0
Do While Not Re.EOF
Risk = Risk & Re!HazardID & ", "
tot=tot+cint(Re!HazardID)
Re.MoveNext
Loop
Me!ID = Left(Risk, Len(Risk) - 2)
msgbox tot


Known is handfull, Unknown is worldfull
 
tty0.. i meant i got it to work.. so thx

vbkris... hmmm that was a strange one.. message boxes popping up giving me strange values and then nothing on the report :)
 
your welcome

anytime

'mi casa es su casa'
]-=tty0=-[
 
msgbox tot is ur total, u have to take it to ur report....

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top