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
| '********************************************************************************************
'*export tous les graph par matricule*************************
'********************************************************************************************
Private Sub Co_export_petitgraph_Click()
Dim GrpApp As Graph.Chart
Dim T As Long
Dim SaisonNm3 As Integer
Dim myconnection As ADODB.Connection
Set myconnection = CurrentProject.Connection
Dim myRecordset As New ADODB.Recordset
myRecordset.ActiveConnection = myconnection
Dim Chemin As String
Dim Erreur As String
Dim matric As Long
On Error GoTo Erreur
'choisi l'adresse selon case a cocher splash
Chemin = "T:\Nivalis\cartographie\graph\"
SaisonNm3 = Li_saison.Value - 3
' requete pour determiner le nombre de boucle
Mysql = "SELECT Table_PDCanneeN.MATRICULE " & _
" FROM Table_PDCanneeN " & _
" where Table_PDCanneeN.saison = " & Li_saison.Value & "" & _
" GROUP BY Table_PDCanneeN.MATRICULE " & _
" ORDER BY Table_PDCanneeN.MATRICULE;"
' éxecute la requete
myRecordset.Open Mysql, , adOpenStatic
' compte le nombre d'enregistrement
T = myRecordset.RecordCount
' positionne sur la premiere ligne
myRecordset.MoveFirst
With Form_Export_graphique
For I = 1 To T
matric = myRecordset.Fields(0)
'modifie la requete Re_CH_Inventaire_PetitGraphGGAttribReal en fonction du matricule
MySql1 = " SELECT re_GG_attr.saison, re_gg_massif.matricule, re_GG_attr.espece, re_gg_massif.massifs, Sum(re_GG_attr.SommeDeattribution_totale) AS Attributions, Sum(re_GG_carton.SommeDeNOMBRE) AS Prélèvements " & _
" FROM (re_GG_attr LEFT JOIN re_GG_carton ON (re_GG_attr.saison = re_GG_carton.SAISON) AND (re_GG_attr.matricule = re_GG_carton.MATRICULE_EXCEL) AND (re_GG_attr.espece = re_GG_carton.ESPECE)) LEFT JOIN re_gg_massif ON re_GG_attr.matricule = re_gg_massif.matricule " & _
" GROUP BY re_GG_attr.saison, re_gg_massif.matricule, re_GG_attr.espece, re_gg_massif.massifs " & _
" HAVING (((re_GG_attr.saison)>= " & SaisonNm3 & ") AND ((re_gg_massif.matricule)=" & matric & ") AND ((re_GG_attr.espece)='chi'));"
CurrentDb.QueryDefs("Re_CH_Inventaire_PetitGraphGGAttribReal").Sql = MySql1
' export le graph en gif
Set GrpApp = .Graphique_gg.Object
'il me declare une erreur ici "erreur d'execution 1004 erreur définie par l'application ou par l'objet"
GrpApp.Export Chemin & matric & ".GIF", FilterName:="GIF"
Set GrpApp = Nothing
' enregistrement suivant
myRecordset.MoveNext
Next I
'nécessaire sinon erreur OLE :: http://support.microsoft.com/kb/824276/fr
.Graphique_gg.Action = acOLEClose
End With
myRecordset.Close
MsgBox "c'est fini!"
Erreur:
Set GrpApp = Nothing
Me.Graphique_gg.Action = acOLEClose
myRecordset.Close
MsgBox "il y a une erreur"
Exit Sub
End Sub |
Partager