SUM fields based on 3 criteria

filler1

New Member
Joined
Aug 5, 2019
Messages
1
hi,

I have a table containing 5 fields. Date, Factory Name, Item, Quality and volume.
how to sum field "volume" with criteria date, factory name and item ?
how do i get these results to appear in txtsum?

this is the code i wrote

Private Sub kumulatif()

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String

Dim factoryname As String
Dim date As Date
Dim item As String


factoryname = frmproduksi.cmbfname.value
date = frmproduksi.DTpicker.value
item = frmproduksi.cmbitem .value


Set conn = New ADODB.Connection
conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Prog\production.accdb;"
conn.Open

Set rs = New ADODB.Recordset

sql = "SELECT date, factoryname, item, Sum(Volume) AS SumOfVolume FROM tblproduction WHERE date, =" & date & " AND factoryname='" & factoryname & "' AND item ='" & item & "' GROUP BY date, factoryname, item;"


Debug.Print sql
rs.Open sql, conn, adOpenKeyset, adLockOptimistic

Do While Not rs.EOF
Me.txtsum.value = conn.Execute(sql)

rs.MoveNext
Loop

rs.Close
conn.Close

Set rs = Nothing
Set conn = Nothing

End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Can you paste your sql string after it has been built as it looks like you have a comma after the where date, =
 
Upvote 0

Forum statistics

Threads
1,223,693
Messages
6,173,866
Members
452,536
Latest member
Chiz511

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