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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
| Sub extraction()
'On Error GoTo errorHandler
Dim PREVIOUScodeARCH As Long, previousHYPERLINK As String, hyperlienTEXT As String
Dim hyperlien As String, nbSCAN As Integer
nbSCAN = 0
effacementliste
nbenreg = 0
If NbrArg = 0 And NbrARG2 = 0 Then
MsgBox "aucun critère n'a été introduit ==> pas de recherche possible !"
Worksheets("résultats").boutonimprimer.Enabled = False
Exit Sub
End If
Worksheets("résultats").sqlVERIF = MonjeuEnregdécroissant
Application.ScreenUpdating = False
Set ADOConnection = New ADODB.Connection
ADOConnection.Open ConnectString
'La requete MySQL dans ta table
Str = MonjeuEnregdécroissant
'Str = "SELECT DISTINCT plans.*, archivesTYPEdoc.typededocument, archivesTYPEdoc.Date, archivesSCANS.lien, archivesSCANS.taillefichier, archivesSCANS.lienOK FROM (((plans INNER JOIN archivesTYPEdoc ON plans.[code plan] = archivesTYPEdoc.[code plan]) INNER JOIN ("
'Str = Str & "SELECT DISTINCT [signets des plans].[code plan] FROM [signets des plans] WHERE (([signets des plans].[code signet])=" & Chr(39) & "54015980XI" & Chr(39) & ") ORDER BY [signets des plans].[code plan]"
'Str = Str & ") AS monSQL ON plans.[code plan] = monSQL.[code plan]) INNER JOIN ([atlas des routes de D142] INNER JOIN [communes des plans] ON [atlas des routes de D142].[code atlas] = [communes des plans].[code atlas]) ON monSQL.[code plan] = [communes des plans].[code plan]) LEFT JOIN archivesSCANS ON plans.[code plan] = archivesSCANS.[code plan] "
'Str = Str & "WHERE (((archivesTYPEdoc.typeDOCdfltSELECTED)=True) AND ((plans.[ancien n° plan compilé])=" & Chr(39) & "Z16927" & Chr(39) & "))"
k = 3
Set adorecordset = ADOConnection.Execute(Str)
'Set adorecordset = New ADODB.Recordset
'adorecordset.Open Str, ADOConnection, adOpenKeyset, adLockOptimistic, adCmdText
adorecordset.MoveLast
If adorecordset.BOF = adorecordset.EOF Then GoTo EXTRACTIONfin
'si le nombre d'enregistrement sélectionné est supérieur à 1000 alors on demande de rendre la recherche plus restritive
If adorecordset.RecordCount > 1000 Then
MsgBox "vos critères ne sont pas assez rectrictif, " & adorecordset.RecordCount & " enregistrements ont été sélectionnés !" & Chr(13) & Chr(13) & "Veuillez affiner votre recherche SVP !"
Worksheets("résultats").boutonimprimer.Enabled = False
GoTo EXTRACTIONfin
End If
If adorecordset.RecordCount = 0 Then 'pas d'enregistrement trouvé
MsgBox "aucun enregistrement sélectionné !"
Worksheets("résultats").boutonimprimer.Enabled = False
GoTo EXTRACTIONfin
Else ' il y a entre 1 et 1000 enregistrements trouvés
'On se place sur le 1er enegistrement
adorecordset.MoveFirst
'Début de la boucle pour extraire les résultats
Do While Not adorecordset.EOF()
' on vérifie si le lien hypertexte n'est pas identique au précédent
If adorecordset![lien] = previousHYPERLINK Then GoTo EXITcurrentARCH
If adorecordset![code plan] = PREVIOUScodeARCH Then
GoTo extractionLIEN
Else
nbSCAN = 0
End If
If adorecordset![code plan] = PREVIOUScodeARCH Then GoTo extractionLIEN
Select Case adorecordset![typededocument]
Case 1
Cells(k, 1) = "Autre"
Case 2
Cells(k, 1) = "Brochure technique"
Case 3
Cells(k, 1) = "Cahier spécial des charges"
Case 4
Cells(k, 1) = "Convention"
Case 5
Cells(k, 1) = "Croquis A4"
Case 6
Cells(k, 1) = "D.I.U."
Case 7
Cells(k, 1) = "Métré"
Case 8
Cells(k, 1) = "Note de calcul"
Case 9
Cells(k, 1) = "Photo"
Case 10
Cells(k, 1) = "Plan"
Case 11
Cells(k, 1) = "Rapport d'inspection"
Case 12
Cells(k, 1) = "Remise de prix"
Case 13
Cells(k, 1) = "Epreuve de pont"
Case 14
Cells(k, 1) = "Bordereau des aciers"
Case 15
Cells(k, 1) = "Dossier"
Case 30
Cells(k, 1) = "reprises/remises de voiries"
End Select
If adorecordset![présent dans clabo ?] = 0 Then
Cells(k, 2) = "à vérifier"
End If
If adorecordset![présent dans clabo ?] = 1 Then
Cells(k, 2) = "oui"
Cells(k, 2).Font.ColorIndex = 2
Cells(k, 2).Interior.ColorIndex = 50
End If
If adorecordset![présent dans clabo ?] = 2 Then
Cells(k, 2) = "manquant"
Cells(k, 2).Font.ColorIndex = 2
Cells(k, 2).Interior.ColorIndex = 3
End If
If adorecordset![présent dans clabo ?] = 3 Then
Cells(k, 2).Font.ColorIndex = 2
Cells(k, 2).Interior.ColorIndex = 45
Cells(k, 2) = "détruit"
End If
If adorecordset![présent dans clabo ?] = 4 Then
Cells(k, 2).Font.ColorIndex = 2
Cells(k, 2).Interior.ColorIndex = 37
Cells(k, 2) = "virtuel"
End If
Cells(k, 3) = adorecordset![Date]
Cells(k, 4) = adorecordset![n° plan compilé]
Cells(k, 5) = adorecordset![ancien n° plan compilé]
Cells(k, 6) = adorecordset![Intitulé]
Cells(k, 7) = adorecordset![caractéristiques]
Cells(k, 8) = adorecordset![commentaires]
extractionLIEN:
If adorecordset![lien] <> "" Then
If adorecordset![lienOK] <> 1 Then 'le lien est réputé corrompu ou trop long pour être suivi
If adorecordset![lienOK] = 0 Then hyperlienTEXT = "LIEN CORROMPU" '"corrompu";0;"OK";1;"trop long";2
If adorecordset![lienOK] = 2 Then hyperlienTEXT = "LIEN trop long pour être suivi"
Cells(k, 9).Value = hyperlienTEXT
Cells(k, 9).Font.ColorIndex = 3 'on affiche le texte en rouge pour attirer l'attention
Else
nbSCAN = nbSCAN + 1
hyperlienTEXT = "LIEN - " & nbSCAN
hyperlien = CStr(adorecordset![lien])
hyperlien = scanpath & hyperlien
With Worksheets(1)
.Hyperlinks.Add Anchor:=.Cells(k, 9), _
Address:=hyperlien, _
ScreenTip:=hyperlien, _
TextToDisplay:=hyperlienTEXT
End With
End If
End If
''extractionLIEN:
''If adorecordset![lien] <> "" Then
''hyperlien = CStr(adorecordset![lien])
''hyperlien = scanpath & hyperlien
''With Worksheets(1)
''.Hyperlinks.Add Anchor:=.Cells(k, 9), _
''Address:=hyperlien, _
''ScreenTip:=hyperlien, _
''TextToDisplay:=hyperlien
''End With
''End If
Cells(k, 10) = adorecordset![taillefichier]
If adorecordset![code plan] = PREVIOUScodeARCH Then GoTo FORnextARCH
Select Case adorecordset![conformitéduplaninsitu]
Case 0
Cells(k, 11) = "ND"
Case 1
Cells(k, 11) = "à vérifier"
Case 2
Cells(k, 11) = "partielle"
Case 3
Cells(k, 11) = "totale"
Case 4
Cells(k, 11) = "non réalisé"
Case 5
Cells(k, 11) = "vérification inutile"
End Select
FORnextARCH:
PREVIOUScodeARCH = adorecordset![code plan]
previousHYPERLINK = adorecordset![lien]
k = k + 1
EXITcurrentARCH:
adorecordset.MoveNext
Loop
Worksheets("résultats").boutonimprimer.Enabled = True
Worksheets("résultats").boutonexporter.Enabled = True
Worksheets("résultats").boutonenvoyerparmail.Enabled = False
'Fin de la boucle
End If
nbenreg = Val(adorecordset.RecordCount)
MsgBox adorecordset.RecordCount & " enregistrement(s) trouvé(s)."
'Fin de la connexion
EXTRACTIONfin:
Set ADOConnection = Nothing
Set adorecordset = Nothing
ADOConnection.Close
Application.ScreenUpdating = True
Exit Sub
errorHandler:
'indique le numéro et la description de l'erreur survenue
MsgBox Err.Number & vbLf & Err.Description & Chr(13) & Chr(13) & "Veuillez noter le message d'erreur et le communiquer à votre administrateur - merci."
End Sub |
Partager