pedie
Well-known Member
- Joined
- Apr 28, 2010
- Messages
- 3,875
Currently i have this code to sum my data check 4 to 5 conditions....by looping though...
How can i simply this kind of code, without having to loop everytime...
Any help will be very much appriciated.
Thanks
Pedie
How can i simply this kind of code, without having to loop everytime...
Any help will be very much appriciated.
Thanks
Pedie
Code:
[/FONT]
[FONT=Courier New]Sub testSum()
Dim rst As DAO.Recordset
Dim MySum As Currency
MySum = 0
Set rst = CurrentDb.OpenRecordset("AllExpDatas", dbOpenDynaset)
rst.MoveFirst
Do Until rst.EOF
Dim yearv As Integer
yearv = Me.ex_Year.Value
'sum where cositions are dl nbk, site, approval = approved, quauter, year = x yeaR
If rst!STD_ID = Me.STD_ID.Value And rst!MyYear = yearv And _
rst!Qv = Me.Qv.Value And rst!Sites = Me.Sites.Value And _
rst!StatusV = "Approved" Then[/FONT]
[FONT=Courier New] MySum = MySum + rst!Expense_Amount
End If
rst.MoveNext
Loop[/FONT]
[FONT=Courier New]rst.Close
Set rst = Nothing
MsgBox "Total expense = " & MySum[/FONT]
[FONT=Courier New]End Sub[/FONT]
[FONT=Courier New]
[/FONT]
[FONT=Courier New]