Sub LectureAccess3()
ChDir ActiveWorkbook.Path
Dim rs As New ADODB.Recordset
Dim MaReq As String
Set cnn = New ADODB.Connection
cnn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=Access2000.mdb"
MaReq = "SELECT count(*) AS Nb FROM client where ville " & listVilles("LectureADO2", "B")
rs.Open MaReq, cnn
Cells(1, 1) = rs("Nb")
rs.Close
cnn.Close
End Sub
Function listVilles(Feuille As String, Colonne As String)
Dim i As Long, listV As String
listV = "in("
With Worksheets(Feuille)
For i = 1 To Application.WorksheetFunction.CountA(.Range(Colonne & ":" & Colonne))
listV = listV & "'" & .Cells(i, 2).Value & "',"
Next i
listVilles = Left(listV, Len(listV) - 1) & ")"
End With
End Function