Question : Sum if from access data base

Hello all,

I would like to have the sum of all line that have this criteria bellow:
oRST2.Filter = "Période = '" & ComDateDisponible.Text & "' & Description_du_produit = '" & Des_prod.Text & "'"

If these 2 criteria exist, it will take the sum of the rows and put the result in my textbox: txtQtedejaassigne.text.

How can i do this please?

Thanks again
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
If Des_prod.Text <> "" Then
Dim sSQL2 As String
 Dim oRST2 As ADODB.Recordset
  Set oRST2 = New ADODB.Recordset
    Dim oConnect2 As ADODB.Connection
  Set oConnect2 = New ADODB.Connection

sSQL2 = "SELECT [Période], [Description_du_produit], [Quantité_assignée] FROM [Distribution employé]"
oConnect2.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & Form4.txtBaseDe.Text & ";"

oRST2.Open sSQL2, oConnect2

If Des_prod > "" Then
oRST2.Filter = "Période = '" & ComDateDisponible.Text & "' & Description_du_produit = '" & Des_prod.Text & "'"
     
        
 
        
    End If
    
 End If

Answer : Sum if from access data base

» I will try to find another way.

The snippet below is inspired by your own code in the question body. Perhaps this is the sort of coding you were looking for?

(°v°)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
    Dim sSQL2 As String
    Dim oRST2 As ADODB.Recordset
    Dim oConnect2 As ADODB.Connection
    
    Set oRST2 = New ADODB.Recordset
    Set oConnect2 = New ADODB.Connection

    sSQL2 _
        = " SELECT Sum([Quantité_assignée])" _
        & " FROM [Distribution employé]" _
        & " WHERE Période = '" & ComDateDisponible.Text & "'" _
        & "   AND Description_du_produit = '" & Des_prod.Text & "'"

    oConnect2.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
        "Data Source=" & Form4.txtBaseDe.Text & ";"

    oRST2.Open sSQL2, oConnect2

    MsgBox oRST2.Fields(0).Value
Random Solutions  
 
programming4us programming4us