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
| Sub CompleteTableau()
'Déclaration des variables
Dim cnx As ADODB.Connection
Dim rst As ADODB.Recordset
'Instanciation des variables
Set cnx = New ADODB.Connection
Set rst = New ADODB.Recordset
Dim sql1 As String
Dim debutperiode As Date
Dim ddeb As String
Dim dfin As String
Dim i As Integer
Dim result_sql
cnx.ConnectionString = "DSN=Stats;UID=***;PWD=***;"
cnx.Open
i = 1
'Changer la date de début d'année
For debutperiode = DateSerial(2008, 12, 29) To DateSerial(2009, 1, 4) Step 7
ddeb = Format(debutperiode, "dd/mm/yyyy")
dfin = Format(debutperiode + 6, "dd/mm/yyyy")
'Nombre total d'envois périodique (courrier ):
sql1 = "select count(*), c.do_co_l, cdr_ty_se_c" + _
" from e_cde_report r , e_cde_document_report d, e_document_composante c" + _
" where cdr_ty_se_c in ('WV2')" + _
" and cdr_ab_nume <> '0003'" + _
" and cdr_d between to_date('" + ddeb + "' , 'dd/mm/yyyy')" + _
" and to_date('" + dfin + "', 'dd/mm/yyyy')" + _
" and r.cdr_c = d.cdr_do_cde_c and r.cdr_ty_se_c = d.cdr_do_ty_se_c and r.cdr_d = d.cdr_do_d" + _
" and c.do_co_ty_do_c = d.cdr_do_ty_do_c and c.do_co_c = d.cdr_do_co_do_c" + _
" group by c.do_co_l, cdr_ty_se_c"
rst.Open sql1, cnx
Range("A" & i).Select
result_sql = rst.Fields(0).Value
ActiveCell.FormulaR1C1 = result_sql
rst.Close
i = i + 10
Next
End Sub |
Partager