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
| Sub Recup_donnees_access()
'
' Recup_donnees_access Macro
' Macro permettant de recuperer les donnes de la table tarification
'
'Declaration
Dim Db As DAO.Database
Dim Rs As DAO.Recordset
Dim strSQL As String
Dim Indice_parcours As Integer
Dim Date_parcours As Variant
Dim Nb_Lignes As Integer
Dim Year1 As String
Dim Year2 As String
'Nettoyage de la feuille
Sheets("Données").Select
Range("A2:AK5000").Select
Selection.ClearContents
Year1 = CStr(Application.InputBox(Prompt:="Entrez la première année:", Title:="Spcification d'année", Type:=2))
' Validation de la première année
If Not Len(Year1) = 4 Then
MsgBox "L'année n'est pas bonne."
Exit Sub
End If
Year2 = CStr(Application.InputBox(Prompt:="Entrez la deuxième année:", Title:="Spcification d'année", Type:=2))
' Validation de la première année
If Not Len(Year2) = 4 Then
MsgBox "L'année n'est pas bonne."
Exit Sub
End If
'Requete permettant de récuperer les champs
Set Db = DAO.OpenDatabase("J:\cr\PoleChiffres\Technique\TecCollec\COMMUN\access\BDD Actuariat Frontale.mdb")
strSQL = "SELECT [N° ETUDE ACTUARIAT], [N° ETUDE OUTIL DE SAISIE], [SOCIETE], [Nom], [RISQUE(S) COUVERT(S)], " & _
"[Effectifs non cadre], [Age moy non cadre], [Effectif Cadre], [Age moy cadre], [Effectif ETAM], " & _
"[Age moy ETAM], [Effectif retraité], [Reçu le], [TECHNICIEN(NE)], [RT ?], [RT Exploitables ?], " & _
"[Effet des RT], [Revue de contrat], [Info concurence], [Alignement],[Liste des courtiers], " & _
"[Portefeuille], [Realisé DI], [Réalisé FM], [sans suite] FROM [base de tarification] " & _
"WHERE [Reçu le] BETWEEN #01/01/" & Right(Year1, 2) & "# AND #31/12/" & Right(Year2, 2) & "#"
Set Rs = Db.OpenRecordset(strSQL, DAO.dbOpenSnapshot)
Range("A2").CopyFromRecordset Rs
Db.Close
'Calcul de différents champs (mois, année, effectif total,..)
Indice_parcours = 2
Nb_Lignes = Range("A65536").End(xlUp).Row
Do
'Calcul du mois et de l'année
Date_parcours = Cells(Indice_parcours, 13)
Cells(Indice_parcours, 26) = DatePart("m", Date_parcours)
Cells(Indice_parcours, 27) = DatePart("yyyy", Date_parcours)
'Calcul de l'effectif total
Cells(Indice_parcours, 28) = Cells(Indice_parcours, 6) + Cells(Indice_parcours, 8) + Cells(Indice_parcours, 10)
'Un identifiant est attribué à chaque dossier en fonction de l'effectif total
If Cells(Indice_parcours, 28) <= 300 Then
Cells(Indice_parcours, 29) = 1
ElseIf Cells(Indice_parcours, 28) > 1000 Then
Cells(Indice_parcours, 29) = 3
Else
Cells(Indice_parcours, 29) = 2
End If
Indice_parcours = Indice_parcours + 1
Loop Until Indice_parcours = Nb_Lignes + 1
'Mise à jour des tableaux
Sheets("Tableau3").Visible = True
Sheets("Tableau3").Select
Range("A4").Select
ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Annee de reception").CurrentPage = Year1
ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotCache.Refresh
ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotFields("Annee de reception").CurrentPage = Year2
ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotCache.Refresh
ActiveWindow.SelectedSheets.Visible = False
Sheets("Tableau2").Visible = True
Sheets("Tableau2").Select
Range("A4").Select
ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Annee de reception").CurrentPage = Year1
ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotCache.Refresh
ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotFields("Annee de reception").CurrentPage = Year2
ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotCache.Refresh
ActiveWindow.SelectedSheets.Visible = False
Sheets("Tableau").Visible = True
Sheets("Tableau").Select
Range("A4").Select
ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Annee de reception").CurrentPage = Year1
ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotCache.Refresh
ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotFields("Annee de reception").CurrentPage = Year2
ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotCache.Refresh
ActiveWindow.SelectedSheets.Visible = False
End Sub |
Partager