Sub affiche()
UserForm2.ListCompt.Column = LST
UserForm2.Show
End Sub
Function LST()
Dim SQL As String
With CreateObject("Adodb.connection")
.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.FullName & ";Extended Properties=""Excel 12.0;HDR=YES;"""
SQL = "SELECT Années, Espece, sum(CD),sum(FA),sum(AD),sum(CH),Sum(RT),Sum(adoptable),Sum(NAdoptable),Sum(DateDc) FROM (" & vbCrLf
SQL = SQL & "SELECT DISTINCT NoDossier, FORMAT([Date],'yyyy') AS Années, [Espece], 1 AS CD, 0 AS FA,0 as AD,0 as CH,0 as RT,0 as adoptable,0 as NAdoptable,0 as DateDc FROM [BD$] WHERE UCASE([Cat#]) = 'CD'" & vbCrLf
SQL = SQL & "UNION ALL" & vbCrLf
SQL = SQL & "SELECT DISTINCT NoDossier, FORMAT([Date],'yyyy') AS Années, [Espece], 0 AS CD, 1 AS FA ,0 as AD,0 as CH,0 as RT,0 as adoptable,0 as NAdoptable,0 as DateDc FROM [BD$] WHERE UCASE([Cat#]) = 'FA'" & vbCrLf
SQL = SQL & "UNION ALL" & vbCrLf
SQL = SQL & "SELECT DISTINCT NoDossier, FORMAT([Date],'yyyy') AS Années, [Espece], 0 AS CD, 0 AS FA,1 as AD,0 as CH,0 as RT,0 as adoptable,0 as NAdoptable,0 as DateDc FROM [BD$] WHERE UCASE([Cat#]) = 'AD'" & vbCrLf
SQL = SQL & "UNION ALL" & vbCrLf
SQL = SQL & "SELECT DISTINCT NoDossier, FORMAT([Date],'yyyy') AS Années, [Espece], 0 AS CD, 0 AS FA,0 as AD,1 as CH,0 as RT,0 as adoptable,0 as NAdoptable,0 as DateDc FROM [BD$] WHERE UCASE([Cat#]) = 'CH'" & vbCrLf
SQL = SQL & "UNION ALL" & vbCrLf
SQL = SQL & "SELECT DISTINCT NoDossier, FORMAT([Date],'yyyy') AS Années, [Espece], 0 AS CD, 0 AS FA,0 as AD,0 as CH,1 as RT ,0 as adoptable,0 as NAdoptable,0 as DateDc FROM [BD$] WHERE UCASE([Cat#]) = 'RT'" & vbCrLf
SQL = SQL & "UNION ALL" & vbCrLf
SQL = SQL & "SELECT DISTINCT NoDossier, FORMAT([Date],'yyyy') AS Années, [Espece], 0 AS CD, 0 AS FA,0 as AD,0 as CH,0 as RT,1 as adoptable,0 as NAdoptable,0 as DateDc FROM [BD$] WHERE UCASE([Caractere]) = UCASE('Adoptable')" & vbCrLf
SQL = SQL & "UNION ALL" & vbCrLf
SQL = SQL & "SELECT DISTINCT NoDossier, FORMAT([Date],'yyyy') AS Années, [Espece], 0 AS CD, 0 AS FA,0 as AD,0 as CH,0 as RT,0 as adoptable,1 as NAdoptable,0 as DateDc FROM [BD$] WHERE UCASE([Caractere]) = UCASE('Non Adoptable')" & vbCrLf
SQL = SQL & "UNION ALL" & vbCrLf
SQL = SQL & "SELECT DISTINCT NoDossier, FORMAT([Date],'yyyy') AS Années, [Espece], 0 AS CD, 0 AS FA,0 as AD,0 as CH,0 as RT,0 as adoptable, 0 As NAdoptable,1 as DateDc FROM [BD$] WHERE [DateDc] is not null" & vbCrLf
SQL = SQL & ") AS SubQuery GROUP BY Années, Espece"
LST = .Execute(SQL).getrows
End With
End Function