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
|
Public Sub rel_incomplets(ByVal creneau As String)
ActiveWorkbook.Sheets("Accueil").Unprotect
cejour = Format(VBA.Date, "dddd")
cejour = cejour & "_" & creneau
nom_feuille = "Rappels_" & creneau
Dim Cn As ADODB.connection
Dim feuille As String, strSQL, texteSQL As String
feuille = "Liste_CU"
f_horaire = "horaires"
Set Cn = New ADODB.connection
With Cn
.Provider = "MSDASQL"
.ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};" & _
"DBQ=" & fichier & "; ReadOnly=False;"
.Open
End With
'------------------------------------------------------
Dim finref, plage As String
finref = classeur.Sheets(nom_feuille).Cells(4, 1).CurrentRegion.Address(True, True, xlR1C1)
finref = Mid(finref, InStr(finref, ":")) 'on ne prend que apres les :
finref = Left(finref, InStr(finref, "C") - 1)
finref = Mid(finref, 3)
If finref > 4 Then
plage = "A5:S" & finref
classeur.Sheets(nom_feuille).Range(plage).ClearContents
End If
texteSQL = "SELECT reference, insee, formulaire, date_rel, cerfa, cadastre, masse, puissance, parcelle, chemin, er_appel, contact_1er_appel"
texteSQL = texteSQL & ", relance1, contact_relance1, relance2, contact_relance2, renvoie, contact_renvoie, commentaire "
texteSQL = texteSQL & "FROM [" & feuille & "$] WHERE date_rel <= #" & dateSQL(VBA.Date) & "#"
texteSQL = texteSQL & " AND insee IN (SELECT insee FROM [" & f_horaire & "$] WHERE " & cejour & " <> null)"
texteSQL = texteSQL & " ORDER BY date_rel;"
MsgBox texteSQL
Set rst = New ADODB.Recordset
rst.Open texteSQL, Cn, adOpenStatic
' Ecrit le résultat de la requête dans la cellule A5
ActiveWorkbook.Sheets(nom_feuille).Range("A5").CopyFromRecordset rst
' Met à jour le compteur sur la page d'accueil
If creneau = "mat" Then
ActiveWorkbook.Sheets("Accueil").Cells(5, 9).Value = rst.RecordCount
Else
ActiveWorkbook.Sheets("Accueil").Cells(6, 9).Value = rst.RecordCount
End If
Cn.Close
Set Cn = Nothing
End sub |
Partager