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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| Dim rs As New ADODB.Recordset
Dim cnx As New ADODB.Connection
Dim lin As Integer
Dim r As Integer
Dim sql_string As String
Sub Webgdo()
Set cnx = New ADODB.Connection
cnx.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver} ;" _
& "SERVER= 111.11.11.11;" _
& "DATABASE= xxx; " _
& "UID= xxx; " _
& "PWD= xxx"
cnx.Open
'`collecte_imputation`.imputation "
' , `collecte_imputation`.realiser
' , `Imputations`.Description
' , `com`.commune
sql_string = "SELECT `collecte_imputation`.realiser" & _
", `Imputations`.Description" & _
", `collecte_imputation`.imputation" & _
", `com`.commune" & _
", `BT`.numero " & _
", SUM(`collecte_imputation`.tps_total)" & _
"FROM " & _
"(((`0147nolor`.Imputations `Imputations` INNER JOIN " & _
"`0147nolor`.collecte_imputation `collecte_imputation` ON (`collecte_imputation`.imputation = `Imputations`.Imputation)) INNER JOIN " & _
"`0147nolor`.BT `BT` ON (`collecte_imputation`.num_bon = `BT`.numero)) INNER JOIN " & _
"`0147nolor`.com `com` ON (`BT`.`09commune` = `com`.codePostal)) " & _
"WHERE (`collecte_imputation`.tps_total <> '0000') AND (`collecte_imputation`.tps_total <> '') AND (`collecte_imputation`.imputation <> '')" & _
"GROUP BY `BT`.numero DESC"
rs.Open sql_string, cnx
Application.ScreenUpdating = False
'Sheets("Table").Value = rs
Range("A1").Value = rs(0).Name
Range("B1").Value = rs(1).Name
Range("C1").Value = rs(2).Name
Range("D1").Value = rs(3).Name
Range("E1").Value = rs(4).Name
Range("F1").Value = rs(5).Name
lin = 2
Do While Not rs.EOF
Cells(lin, 1).Value = rs(0).Value
Cells(lin, 2).Value = rs(1).Value
Cells(lin, 3).Value = rs(2).Value
Cells(lin, 4).Value = rs(3).Value
Cells(lin, 5).Value = rs(4).Value
Cells(lin, 6).Value = rs(5).Value
lin = lin + 1
rs.MoveNext
Loop
rs.Close
cnx.Close
Application.ScreenUpdating = True
End Sub |
Partager