Private Sub CBAddition_Click()
Dim CNX As Object
Dim I As Integer, RS, CNT
Dim Réponse As Variant
Dim Mémoire As Boolean
Mémoire = True
Const SQL As String = "SELECT * FROM AttestationTVAMontantTTC;"
Const CNXString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=?;Extended Properties=""Excel 12.0 Macro;HDR=YES"";"
For I = 0 To LBListeFacture.ListCount - 1
If Me.LBListeFacture.Selected(I) Then
Set CNX = CreateObject("ADODB.Connection")
CNX.ConnectionString = Replace(CNXString, "?", Chemin2 & LBListeFacture.List(I))
CNX.CursorLocation = 3
CNX.Open
Set RS = CNX.Execute(SQL)
CNT = CNT + CDbl(RS.Fields(0).Name)
RS.Close: Set RS = Nothing
CNX.Close: Set CNX = Nothing
Me.LBListeFacture.Selected(I) = False
End If
Next
If Mémoire = False Then Réponse = MsgBox("Veuillez sélectionner au moins une facture !", vbInformation, "Attention")
If Réponse = "" Then MsgBox "La somme des factures sélectionnées est de " & Format(CNT, "Currency"), vbInformation, "Résultat": Unload Me
End Sub