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
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