IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Requêtes et SQL. Discussion :

[ACCESS 2002] Historisation données


Sujet :

Requêtes et SQL.

  1. #1
    Membre averti
    Inscrit en
    Août 2007
    Messages
    360
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 360
    Points : 396
    Points
    396
    Par défaut [ACCESS 2002] Historisation données
    Bonjour,

    Je voudrais prendre en compte une historisation des données sous ACCESS.

    Cette discussion fait suite à celle-ci :

    http://www.developpez.net/forums/sho...d.php?t=492065

    En fait, j'ai des utilisateurs (UTILS), répartis dans des groupes (GRPS), et des types d'utilisateurs (TUTILS).

    J'ai donc le schéma suivant :

    GRPS(ID_GRPS,..., A_COMPTER, DATE_DEBUT, DATE_FIN)
    APP_GRPS_UTILS(#ID_GRPS, #ID_UTILS, DATE_DEBUT, DATE_FIN)
    UTILS(#ID_UTILS, ..., A_COMPTER, DATE_DEBUT, DATE_FIN)
    APP_TUTILS_UTILS(#ID_TUTILS, #ID_UTILS, DATE_DEBUT, DATE_FIN)
    TUTILS(ID_TUTILS, ...)

    Jeu d'essai :

    ===========================================
    GRPS
    ===========================================
    1 | Groupe 1 | 1 | 01/01/2007 | 31/12/9999
    -------------------------------------------------------
    2 | Groupe 2 | 1 | 01/01/2007 | 31/12/9999
    -------------------------------------------------------
    3 | Groupe 3 | 0 | 01/01/2007 | 31/12/9999
    -------------------------------------------------------

    ===========================================
    APP_GRPS_UTILS
    ===========================================
    1 | 1 | 01/01/2007 | 10/02/2008
    -------------------------------------------------------
    1 | 2 | 01/01/2007 | 31/12/9999
    -------------------------------------------------------
    1 | 3 | 01/01/2007 | 18/02/2008
    -------------------------------------------------------
    3 | 3 | 18/02/2008 | 31/12/9999
    -------------------------------------------------------
    1 | 4 | 01/01/2007 | 19/02/2008
    -------------------------------------------------------
    2 | 4 | 19/02/2008 | 31/12/9999
    -------------------------------------------------------

    ===========================================
    UTILS
    ===========================================
    1 | A | 0 | 01/01/2007 | 10/02/2008
    -------------------------------------------------------
    2 | B | 1 | 01/01/2007 | 31/12/9999
    -------------------------------------------------------
    3 | C | 1 | 01/01/2007 | 31/12/9999
    -------------------------------------------------------
    4 | D | 1 | 01/01/2007 | 31/12/9999
    -------------------------------------------------------

    ===========================================
    APP_TUTILS_UTILS
    ===========================================
    1 | 1 | 01/01/2007 | 10/02/2008
    -------------------------------------------------------
    1 | 2 | 01/01/2007 | 31/12/9999
    -------------------------------------------------------
    1 | 3 | 01/01/2007 | 18/02/2008
    -------------------------------------------------------
    4 | 3 | 18/02/2008 | 31/12/9999
    -------------------------------------------------------
    1 | 4 | 01/01/2007 | 31/12/9999
    -------------------------------------------------------

    =============
    TUTILS
    =============
    1 | A |
    ---------------
    2 | B |
    ---------------
    3 | C |
    ---------------
    4 | D |
    ---------------

    Certains groupes sont liés aux types d'utilisateurs...

    C'est à dire que si l'utilisateur d'ID 3 ("C"), change de type d'utilisateurs de "A" à "D", il change obligatoirement de groupe (de "A" à "C").

    Alors que, si l'utilisateur d'ID 4 ("D"), change de groupe (de "A" à "B"), il ne change pas forcement de type d'utilisateurs.

    Pour résumer, j'ai des relations 1,1--1,n 1,n--1,1 dépendantes en elles et je ne sais plus comment gérer ceci dans le code VBA.

    Ex :

    Pour modifier un utilisateur, je réalise :
    - UPDATE UTILS
    - Si Changé :
    - UPDATE + INSERT APP_TUTILS_UTILS
    - UPDATE + INSERT APP_GRPS_UTILS

    Y a t-il une méthode plus simple pour gérer l'historisation des données et surtout, m'y suis-je bien pris dans la modélisation ?

    Merci de m'avoir lu,

    A+

  2. #2
    Membre averti
    Inscrit en
    Août 2007
    Messages
    360
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 360
    Points : 396
    Points
    396
    Par défaut
    Re,

    J'ai réussi...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
        '==================================================================================
        ' Valider_Click() : Déclenchée sur OnClick.
        '==================================================================================
        ' * Vérifie les données saisies
        ' * Modifie Utilisateur en cours : HISTORISATION !
        '   - UTILS : UPDATE dans tous les cas
        '   Si Changé (T_UTILS, GRPS):
        '   - APP_TUTILS_UTILS : UPDATE (données obsolètes) + INSERT (nouvelle appartenance)
        '   - APP_GRPS_UTILS : UPDATE + INSERT
        '==================================================================================
     
        Dim strCmd As String
        Dim rst As New ADODB.Recordset
        Dim rst1 As New ADODB.Recordset
     
        If ((txtCode.Value <> "") And (txtNom.Value <> "") And (txtPrenom.Value <> "") And (lstType.ListIndex <> -1)) Then
            ' On Update la table UTILS, mais pas seulement : Historisation
            strCmd = "UPDATE UTILS SET " & _
                        "LOG_UTILS = '" & UCase(txtNom.Value) & "', " & _
                        "PASS_UTILS = '" & txtPass1.Value & "', " & _
                        "NOM_UTILS = '" & UCase(txtNom.Value) & "', " & _
                        "PRM_UTILS = '" & txtPrenom.Value & "' " & _
                        "WHERE ID_UTILS = " & CInt(Form_Gerer_Utilisateurs.lblID.Caption) ' -> Astuce !
            'MsgBox strCmd
            If (Update(strCmd)) Then
                'txtCode.Enabled = True
                'txtCode.SetFocus
                txtMessage.Caption = "MODIFICATION EFFECTUEE !"
                txtMessage.ForeColor = 0
                Form_Gerer_Utilisateurs.Refresh
                '=====================================================================================================================
                ' anciennes informations -> UPDATE
                '=====================================================================================================================
     
                ' On cherche à savoir si le Type d'util a changé
                lstType.SetFocus
                strCmd = "SELECT * FROM TUTILS, APP_TUTILS_UTILS, UTILS " & _
                            "WHERE UTILS.ID_UTILS = APP_TUTILS_UTILS.ID_UTILS AND APP_TUTILS_UTILS.ID_TUTILS = TUTILS.ID_TUTILS " & _
                            "AND UTILS.ID_UTILS = " & CInt(Form_Gerer_Utilisateurs.lblID.Caption) & _
                            " AND APP_TUTILS_UTILS.DATE_FIN > #" & CDate(Format(Now(), "DD/MM/YYYY")) & "#"
                If (ExecSQL(strCmd, rst)) Then
                    If (rst.Fields("LBL_TUTILS").Value <> lstType.Text) Then
                        ' On Update les anciennes informations (DATE_FIN), celles qui étaient valides jusqu'alors
                        strCmd = "UPDATE APP_TUTILS_UTILS SET DATE_FIN = #" & CDate(Format(Now(), "DD/MM/YYYY")) & "# " & _
                                    "WHERE ID_UTILS = " & CInt(rst.Fields("UTILS.ID_UTILS").Value) & _
                                    " AND ID_TUTILS = " & CInt(rst.Fields("TUTILS.ID_TUTILS").Value) & _
                                    " AND DATE_FIN > #" & CDate(Format(Now(), "DD/MM/YYYY")) & "#"
                        'MsgBox strCmd
                        If (Update(strCmd)) Then
                            'txtCode.Enabled = True
                            'txtCode.SetFocus
                            txtMessage.Caption = "MODIFICATION EFFECTUEE !"
                            txtMessage.ForeColor = 0
                            Form_Gerer_Utilisateurs.Refresh
                        End If
                    End If
                    ' On cherche à savoir si le Groupe a changé
                    If (lstGRPS.Visible = True) Then
                        lstGRPS.SetFocus
                        strCmd = "SELECT * FROM UTILS, APP_GRPS_UTILS, GRPS " & _
                                    "WHERE GRPS.ID_GRPS = APP_GRPS_UTILS.ID_GRPS AND APP_GRPS_UTILS.ID_UTILS = UTILS.ID_UTILS " & _
                                    "AND UTILS.ID_UTILS = " & CInt(Form_Gerer_Utilisateurs.lblID.Caption) & _
                                    " AND APP_GRPS_UTILS.DATE_FIN > #" & CDate(Format(Now(), "DD/MM/YYYY")) & "#"
                        If (ExecSQL(strCmd, rst)) Then
                            If (rst.Fields("LBL_GRPS").Value <> lstGRPS.Text) Then
                                ' On Update les anciennes informations
                                    strCmd = "UPDATE APP_GRPS_UTILS SET DATE_FIN = #" & CDate(Format(Now(), "DD/MM/YYYY")) & "# " & _
                                                "WHERE ID_UTILS = " & CInt(rst.Fields("UTILS.ID_UTILS").Value) & _
                                                " AND ID_GRPS = " & CInt(rst.Fields("GRPS.ID_GRPS").Value) & _
                                                " AND DATE_FIN > #" & CDate(Format(Now(), "DD/MM/YYYY")) & "#"
                                    'MsgBox strCmd
                                If (Update(strCmd)) Then
                                    'txtCode.Enabled = True
                                    'txtCode.SetFocus
                                    txtMessage.Caption = "MODIFICATION EFFECTUEE !"
                                    txtMessage.ForeColor = 0
                                    Form_Gerer_Utilisateurs.Refresh
                                End If
                            End If
     
                            '=====================================================================================================================
                            ' nouvelles informations -> INSERT
                            '=====================================================================================================================
     
                            lstType.SetFocus
                            strCmd = "SELECT * FROM TUTILS WHERE LBL_TUTILS = '" & lstType.Text & "'"
                            If (ExecSQL(strCmd, rst)) Then
                                strCmd = "INSERT INTO APP_TUTILS_UTILS (ID_TUTILS, ID_UTILS, DATE_DEBUT) VALUES(" & _
                                            rst.Fields("ID_TUTILS").Value & ", " & _
                                            CInt(Form_Gerer_Utilisateurs.lblID.Caption) & ", " & _
                                            "#" & CDate(Format(Now(), "DD/MM/YYYY")) & "#)"
                                'MsgBox strCmd
                                If (Update(strCmd)) Then
                                    'txtCode.Enabled = True
                                    'txtCode.SetFocus
                                    txtMessage.Caption = "MODIFICATION EFFECTUEE !"
                                    txtMessage.ForeColor = 0
                                    Form_Gerer_Utilisateurs.Refresh
     
                                    lstGRPS.SetFocus
                                    strCmd = "SELECT ID_GRPS FROM GRPS WHERE CODE_GRPS = '" & lstGRPS.Text & "'"
                                    If (ExecSQL(strCmd, rst)) Then
                                        strCmd = "INSERT INTO APP_GRPS_UTILS (ID_GRPS, ID_UTILS, DATE_DEBUT) VALUES(" & _
                                                    rst.Fields("ID_GRPS").Value & ", " & _
                                                    CInt(Form_Gerer_Utilisateurs.lblID.Caption) & ", " & _
                                                    "#" & CDate(Format(Now(), "DD/MM/YYYY")) & "#)"
                                        'MsgBox strCmd
                                        If (Update(strCmd)) Then
                                            'txtCode.Enabled = True
                                            'txtCode.SetFocus
                                            txtMessage.Caption = "MODIFICATION EFFECTUEE !"
                                            txtMessage.ForeColor = 0
                                            Form_Gerer_Utilisateurs.Refresh
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        Else
            txtMessage.Caption = "SAISISSEZ TOUS LES CHAMPS !"
            txtMessage.ForeColor = 255
        End If
    Pour ceux que ça intéresse...

    A+

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [ACCESS] Connexion base de données Access 2002
    Par developeuz93 dans le forum ASP
    Réponses: 18
    Dernier message: 15/12/2008, 10h44
  2. Réponses: 2
    Dernier message: 13/06/2006, 08h47
  3. [Access 2002] Exporter des données vers une base Access 2.0
    Par SamLeChiseuji dans le forum Access
    Réponses: 27
    Dernier message: 01/06/2006, 11h41
  4. [Access] Base de données corrompue
    Par portu dans le forum Bases de données
    Réponses: 1
    Dernier message: 24/11/2004, 22h02
  5. [Runtime] - Access 2002
    Par Icetea dans le forum Runtime
    Réponses: 4
    Dernier message: 05/10/2004, 14h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo