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

VBA Access Discussion :

Problème de choix multiples avec boutons d'options.


Sujet :

VBA Access

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Octobre 2012
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Octobre 2012
    Messages : 44
    Points : 34
    Points
    34
    Par défaut Problème de choix multiples avec boutons d'options.
    Bonjour à tous,

    Je développe une petite application et je rencontre des difficultés relatives à un choix qui doit être fait dans un formulaire :

    Dans ce formulaire, j'ai disposé 6 cases d'options, permettant de paramétrer une requête SQL dans un recordset.

    Lorsque je coche une case, puis une autre, tout se passe bien, et la requête SQL est correcte. En revanche lorsque je décoche la deuxième case, la requête ne se met pas à jour, et mes petites compétences en VBA ne m'ont pas permis de comprendre pourquoi.

    A noter que plusieurs choix sont possibles, et que la requête (count) affichant le résultat est mise à jour à chaque fois qu'un clic est fait sur une case (cochée ou décochée).

    Je vous joins mon code, car je ne m'en sors pas malheureusement. Pour faire vos essais, il vous suffit juste de créer un formulaire vierge et d'y placer 6 cases d'options qui porteront les noms : opt_1, opt_2, opt_3, opt_4, opt_5 et opt_6.

    J'y ai inséré une MsgBox pour vous rendre compte que la requête ne subit pas la modification attendue.

    J'en appelle donc à votre expertise, et vous en remercie par avance.

    Cordialement.


    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
    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
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    Dim valeur_com As String
    Dim opt_1_and As String: Dim opt_1_table As String: Dim opt_1_champ As String: Dim opt_1_signe As String: Dim opt_1_rep As String
    Dim opt_2_and As String: Dim opt_2_table As String: Dim opt_2_champ As String: Dim opt_2_signe As String: Dim opt_2_rep As String
    Dim opt_3_and As String: Dim opt_3_table As String: Dim opt_3_champ As String: Dim opt_3_signe As String: Dim opt_3_rep As String
    Dim opt_4_and As String: Dim opt_4_table As String: Dim opt_4_champ As String: Dim opt_4_signe As String: Dim opt_4_rep As String
    Dim opt_5_and As String: Dim opt_5_table As String: Dim opt_5_champ As String: Dim opt_5_signe As String: Dim opt_5_rep As String
    Dim opt_6_and As String: Dim opt_6_table As String: Dim opt_6_champ As String: Dim opt_6_signe As String: Dim opt_6_rep As String
     
    Dim SQL_Q1P4 As String
     
    Private Sub Form_Open(Cancel As Integer)
     
    Me.opt_1.Value = 0
    Me.opt_2.Value = 0
    Me.opt_3.Value = 0
    Me.opt_4.Value = 0
    Me.opt_5.Value = 0
    Me.opt_6.Value = 0
    valeur_com = "BIRC18"
     
    End Sub
     
    Private Sub opt_1_Click()
     
    Me.Refresh
     
    If Me.opt_1.Value = True Then
     
        If opt_1_and = " and [" Or opt_2_and = " and [" Or opt_3_and = " and [" Or opt_4_and = " and [" Or opt_5_and = " and [" Or opt_6_and = " and [" Then
        opt_1_and = " or ["
        opt_1_table = valeur_com
        opt_1_champ = "].[Q1T]"
        opt_1_signe = "="
        opt_1_rep = Chr(34) & 1 & Chr(34)
     
        Else
     
        opt_1_and = " and ["
        opt_1_table = valeur_com
        opt_1_champ = "].[Q1T]"
        opt_1_signe = "="
        opt_1_rep = Chr(34) & 1 & Chr(34)
     
        End If
     
    Else
     
    opt_1_and = ""
    opt_1_table = ""
    opt_1_champ = ""
    opt_1_signe = ""
    opt_1_rep = ""
     
    End If
     
    If Me.opt_2.Value = True Then
     
        If opt_1_and = " and [" Or opt_2_and = " and [" Or opt_3_and = " and [" Or opt_4_and = " and [" Or opt_5_and = " and [" Or opt_6_and = " and [" Then
        opt_2_and = " or ["
        opt_2_table = valeur_com
        opt_2_champ = "].[Q1T]"
        opt_2_signe = "="
        opt_2_rep = Chr(34) & 2 & Chr(34)
     
        Else
     
        opt_2_and = " and ["
        opt_2_table = valeur_com
        opt_2_champ = "].[Q1T]"
        opt_2_signe = "="
        opt_2_rep = Chr(34) & 2 & Chr(34)
     
        End If
     
    Else
     
    opt_2_and = ""
    opt_2_table = ""
    opt_2_champ = ""
    opt_2_signe = ""
    opt_2_rep = ""
     
    End If
     
    If Me.opt_3.Value = True Then
     
        If opt_2_and = " and [" Or opt_1_and = " and [" Or opt_3_and = " and [" Or opt_4_and = " and [" Or opt_5_and = " and [" Or opt_6_and = " and [" Then
        opt_3_and = " or ["
        opt_3_table = valeur_com
        opt_3_champ = "].[Q1T]"
        opt_3_signe = "="
        opt_3_rep = Chr(34) & 3 & Chr(34)
     
        Else
     
        opt_3_and = " and ["
        opt_3_table = valeur_com
        opt_3_champ = "].[Q1T]"
        opt_3_signe = "="
        opt_3_rep = Chr(34) & 3 & Chr(34)
     
        End If
     
    Else
     
    opt_3_and = ""
    opt_3_table = ""
    opt_3_champ = ""
    opt_3_signe = ""
    opt_3_rep = ""
     
    End If
     
    If Me.opt_4.Value = True Then
     
        If opt_2_and = " and [" Or opt_3_and = " and [" Or opt_1_and = " and [" Or opt_4_and = " and [" Or opt_5_and = " and [" Or opt_6_and = " and [" Then
        opt_4_and = " or ["
        opt_4_table = valeur_com
        opt_4_champ = "].[Q1T]"
        opt_4_signe = "="
        opt_4_rep = Chr(34) & 4 & Chr(34)
     
        Else
     
        opt_4_and = " and ["
        opt_4_table = valeur_com
        opt_4_champ = "].[Q1T]"
        opt_4_signe = "="
        opt_4_rep = Chr(34) & 4 & Chr(34)
     
        End If
     
    Else
     
    opt_4_and = ""
    opt_4_table = ""
    opt_4_champ = ""
    opt_4_signe = ""
    opt_4_rep = ""
     
    End If
     
    If Me.opt_5.Value = True Then
     
        If opt_1_and = " and [" Or opt_2_and = " and [" Or opt_3_and = " and [" Or opt_4_and = " and [" Or opt_5_and = " and [" Or opt_6_and = " and [" Then
        opt_5_and = " or ["
        opt_5_table = valeur_com
        opt_5_champ = "].[Q1T]"
        opt_5_signe = "="
        opt_5_rep = Chr(34) & 5 & Chr(34)
     
        Else
     
        opt_5_and = " and ["
        opt_5_table = valeur_com
        opt_5_champ = "].[Q1T]"
        opt_5_signe = "="
        opt_5_rep = Chr(34) & 5 & Chr(34)
     
        End If
     
    Else
     
    opt_5_and = ""
    opt_5_table = ""
    opt_5_champ = ""
    opt_5_signe = ""
    opt_5_rep = ""
     
    End If
     
    If Me.opt_6.Value = True Then
     
        If opt_1_and = " and [" Or opt_2_and = " and [" Or opt_3_and = " and [" Or opt_4_and = " and [" Or opt_5_and = " and [" Or opt_6_and = " and [" Then
        opt_6_and = " or ["
        opt_6_table = valeur_com
        opt_6_champ = "].[Q1T]"
        opt_6_signe = "="
        opt_6_rep = Chr(34) & 6 & Chr(34)
     
        Else
     
        opt_6_and = " and ["
        opt_6_table = valeur_com
        opt_6_champ = "].[Q1T]"
        opt_6_signe = "="
        opt_6_rep = Chr(34) & 6 & Chr(34)
     
        End If
     
    Else
     
    opt_6_and = ""
    opt_6_table = ""
    opt_6_champ = ""
    opt_6_signe = ""
    opt_6_rep = ""
     
    End If
     
    Me.Refresh
     
    Call Q1P4_Calcul
     
    End Sub
    Private Sub opt_2_Click()
     
    Me.Refresh
     
    Call opt_1_Click
     
    End Sub
    Private Sub opt_3_Click()
     
    Me.Refresh
     
    Call opt_1_Click
     
    End Sub
    Private Sub opt_4_Click()
     
    Me.Refresh
     
    Call opt_1_Click
     
    End Sub
    Private Sub opt_5_Click()
     
    Me.Refresh
     
    Call opt_1_Click
     
    End Sub
    Private Sub opt_6_Click()
     
    Me.Refresh
     
    Call opt_1_Click
     
    End Sub
    Private Sub Q1P4_Calcul()
     
    If Me.opt_1.Value = 0 And Me.opt_2.Value = 0 And Me.opt_3.Value = 0 And Me.opt_4.Value = 0 And Me.opt_5.Value = 0 And Me.opt_6.Value = 0 Then
     
    opt_1_and = "": opt_1_table = "": opt_1_champ = "": opt_1_signe = "": opt_1_rep = ""
    opt_2_and = "": opt_2_table = "": opt_2_champ = "": opt_2_signe = "": opt_2_rep = ""
    opt_3_and = "": opt_3_table = "": opt_3_champ = "": opt_3_signe = "": opt_3_rep = ""
    opt_4_and = "": opt_4_table = "": opt_4_champ = "": opt_4_signe = "": opt_4_rep = ""
    opt_5_and = "": opt_5_table = "": opt_5_champ = "": opt_5_signe = "": opt_5_rep = ""
    opt_6_and = "": opt_6_table = "": opt_6_champ = "": opt_6_signe = "": opt_6_rep = ""
     
    SQL_Q1P4 = ""
     
    Else
     
    If opt_1_and = " and [" Then
    SQL_Q1P4 = opt_1_and & opt_1_table & opt_1_champ & opt_1_signe & opt_1_rep & opt_2_and & opt_2_table & opt_2_champ & opt_2_signe & opt_2_rep & opt_3_and & opt_3_table & opt_3_champ & opt_3_signe & opt_3_rep & opt_4_and & opt_4_table & opt_4_champ & opt_4_signe & opt_4_rep & opt_5_and & opt_5_table & opt_5_champ & opt_5_signe & opt_5_rep & opt_6_and & opt_6_table & opt_6_champ & opt_6_signe & opt_6_rep
    Else
        If opt_2_and = " and [" Then
        SQL_Q1P4 = opt_2_and & opt_2_table & opt_2_champ & opt_2_signe & opt_2_rep & opt_1_and & opt_1_table & opt_1_champ & opt_1_signe & opt_1_rep & opt_3_and & opt_3_table & opt_3_champ & opt_3_signe & opt_3_rep & opt_4_and & opt_4_table & opt_4_champ & opt_4_signe & opt_4_rep & opt_5_and & opt_5_table & opt_5_champ & opt_5_signe & opt_5_rep & opt_6_and & opt_6_table & opt_6_champ & opt_6_signe & opt_6_rep
        Else
            If opt_3_and = " and [" Then
            SQL_Q1P4 = opt_3_and & opt_3_table & opt_3_champ & opt_3_signe & opt_3_rep & opt_1_and & opt_1_table & opt_1_champ & opt_1_signe & opt_1_rep & opt_2_and & opt_2_table & opt_2_champ & opt_2_signe & opt_2_rep & opt_4_and & opt_4_table & opt_4_champ & opt_4_signe & opt_4_rep & opt_5_and & opt_5_table & opt_5_champ & opt_5_signe & opt_5_rep & opt_6_and & opt_6_table & opt_6_champ & opt_6_signe & opt_6_rep
            Else
                If opt_4_and = " and [" Then
                SQL_Q1P4 = opt_4_and & opt_4_table & opt_4_champ & opt_4_signe & opt_4_rep & opt_5_and & opt_5_table & opt_5_champ & opt_5_signe & opt_5_rep & opt_1_and & opt_1_table & opt_1_champ & opt_1_signe & opt_1_rep & opt_2_and & opt_2_table & opt_2_champ & opt_2_signe & opt_2_rep & opt_3_and & opt_3_table & opt_3_champ & opt_3_signe & opt_3_rep & opt_6_and & opt_6_table & opt_6_champ & opt_6_signe & opt_6_rep
                Else
                    If opt_5_and = " and [" Then
                    SQL_Q1P4 = opt_5_and & opt_5_table & opt_5_champ & opt_5_signe & opt_5_rep & opt_1_and & opt_1_table & opt_1_champ & opt_1_signe & opt_1_rep & opt_2_and & opt_2_table & opt_2_champ & opt_2_signe & opt_2_rep & opt_3_and & opt_3_table & opt_3_champ & opt_3_signe & opt_3_rep & opt_4_and & opt_4_table & opt_4_champ & opt_4_signe & opt_4_rep & opt_6_and & opt_6_table & opt_6_champ & opt_6_signe & opt_6_rep
                    Else
                        If opt_6_and = " and [" Then
                        SQL_Q1P4 = opt_6_and & opt_6_table & opt_6_champ & opt_6_signe & opt_6_rep & opt_1_and & opt_1_table & opt_1_champ & opt_1_signe & opt_1_rep & opt_2_and & opt_2_table & opt_2_champ & opt_2_signe & opt_2_rep & opt_3_and & opt_3_table & opt_3_champ & opt_3_signe & opt_3_rep & opt_4_and & opt_4_table & opt_4_champ & opt_4_signe & opt_4_rep & opt_5_and & opt_5_table & opt_5_champ & opt_5_signe & opt_5_rep
                        Else
                        End If
                    End If
                End If
            End If
        End If
    End If
     
    End If
     
    MsgBox SQL_Q1P4
     
    'Set oDb = CurrentDb
    '    Set oRst = oDb.OpenRecordset(SQL_Q0 & SQL_Q2 & SQL_Q4 & SQL_Q1P4 & SQL_Q2P4, dbOpenSnapshot)
    '    nb_bi = oRst.Fields(0)
     
    '.........................
     
    'oDb.Close
    'Set oDb = Nothing
    'Set oRst = Nothing
     
    Me.Refresh
     
    End Sub

  2. #2
    Expert éminent

    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    3 846
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Madagascar

    Informations forums :
    Inscription : Mai 2012
    Messages : 3 846
    Points : 7 983
    Points
    7 983
    Par défaut
    Bonjour,

    Il faudrait peut-être lancer tes procédures sur les évènements Après Mise à Jour (AfterUpdate) des boutons pour que ça tienne compte des modifications de statut ?

    Cordialement,

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Octobre 2012
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Octobre 2012
    Messages : 44
    Points : 34
    Points
    34
    Par défaut
    Bonjour Madefemere,

    Merci pour ta proposition, mais le résultat reste inchangé, la requête ne se met pas à jour comme elle le devrait.

    Une autre piste peut-être ?

    En tout cas, merci.

    Cordialement.

Discussions similaires

  1. Réponses: 3
    Dernier message: 19/08/2007, 01h45
  2. Réponses: 3
    Dernier message: 30/05/2007, 16h56
  3. [vb6] Frames avec boutons d'option
    Par Asdorve dans le forum VB 6 et antérieur
    Réponses: 8
    Dernier message: 21/07/2006, 15h57
  4. Comment creer un choix multiple avec des cases a cocher ??
    Par pedrosystem dans le forum Access
    Réponses: 5
    Dernier message: 09/03/2006, 10h36

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