1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| Sub DAOOpenRecordset()
Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim wrk As DAO.Workspace
Dim cnx As DAO.Connection
Dim req, chemin, fichier, provider, NomPilote As String
chemin = ThisWorkbook.Path
fichier = ThisWorkbook.Name
NomPilote = fRequete.Range("znRequetePilote")
provider = "ODBC;DSN=" & NomPilote & ";DBQ=" & chemin & "\" & fichier
Set wrk = CreateWorkspace("", "", "", dbUseODBC)
Set cnx = wrk.OpenConnection("", , , provider)
req = fRequete.Range("A127").Value
Set rs = cnx.OpenRecordset(req, dbOpenDynamic)
Dim col, i As Integer
If Not rs.EOF Then
rs.MoveFirst
col = 1
For Each fld In rs.Fields
Feuil2.Cells(1, col) = fld.Name
col = col + 1
Next
For i = 2 To 10
col = 1
For Each fld In rs.Fields
Feuil2.Cells(i, col) = fld.Value
col = col + 1
Next
rs.MoveNext
Next
End If
rs.Close
End Sub |
Partager