Please help me out _ Suming in Access [Is there any easy way?]

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

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]
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top