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 :

Execution du if sans fin


Sujet :

VBA Access

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2007
    Messages : 5
    Par défaut Execution du if sans fin
    bonjour, je suis nouvelle sur le forum

    Je bloque sur un de mes morceaux de code qui fonctionnait tres bien et qui maintenant ne veut plus marcher.

    J'ai une condition if qui ne fait que s'executer plusieurs fois donc message erreur de modifications non effectuées à cause de doublons.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    If missionexist=0 then
       set tmi=bd.openrecordset("mission", db_open_dynaset)
       tmi.addnew
       tmi![nomission]=nomission
       tmi![lieumission]=lieum
       tmi![cpm]=cpm
       tmi![villem]=villem
       tmi.update
    end if
    je vous remercie de votre aide

  2. #2
    Membre émérite Avatar de jean-paul lepetit
    Inscrit en
    Février 2005
    Messages
    849
    Détails du profil
    Informations personnelles :
    Âge : 69

    Informations forums :
    Inscription : Février 2005
    Messages : 849
    Par défaut
    Salut,

    Ce n'est pas le IF qui est en cause,

    tu boucles certainement avant

    Donnes le code complet

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2007
    Messages : 5
    Par défaut
    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
    On Error GoTo GestionErreur:
    GestionErreur:
        If Err.Number = 3421 Then
            MsgBox "Vous avez saisi du texte dans un champ numérique. Veuillez vérifier vos informations.", vbOKOnly, "ATTENTION"
            Exit Sub
        End If
        If Err.Number = 3163 Then
            MsgBox "Vous ne pouvez pas ajouter de motif. Veuillez choisir un motif dans la zone de liste.", vbOKOnly, "ATTENTION"
            Exit Sub
        End If
     
     
    Dim bd As Database
    Dim tage As Recordset, tin As Recordset
    Dim tct As Recordset, tmi As Recordset, treq As Recordset, tverif As Recordset, texist As Recordset
    Dim req As String, verif As String, critere As String, exist As String, critere2 As String
    Dim missionex As String, verifconduct As String, veriftache As String
    Dim tverifconduct As Recordset, tconduct As Recordset, ttache As Recordset, tveriftache As Recordset
    Dim tre As Recordset
     
    Set bd = DBEngine.Workspaces(0).Databases(0)
     
    If Me.noc.Value <> "" Then
        'vérification existence du contrat pr savoir si Nveau ou MAJ
        exist = "select count(nocontrat) as num from contrat where nocontrat='" + Me.noc + "'"
        Set texist = bd.OpenRecordset(exist, DB_OPEN_DYNASET)
     
        If texist![num] = 0 Then
            'enregistrement des différentes données concernant le contrat établi
            'gestion des oublis de remplissage de champs
            If Me.nomagence.Value <> "" Then
                If Me.lieum <> "" Then
                    If Me.basecs.Value <> "" Then
                        If Me.bcr.Value <> "" Then
                            If nosecu.Value <> "" Then
                                If datedebc <> "" And datefinc <> "" Then
                                    If Me.taches <> "" Then
                                        'enregistrement de l'agence intérim si nouvelle
                                        If Me.agenceexist = 0 Then
                                            Set tage = bd.OpenRecordset("agence", DB_OPEN_DYNASET)
     
                                            tage.AddNew
                                            tage![noagence] = Me.noagence
                                            tage![noma] = nomagence.Value
                                            tage![villea] = villa
                                            tage.Update
                                        End If
     
                                        'enregistrement de la mission si nouvelle
                                        If missionexist = 0 Then
                                            Set tmi = bd.OpenRecordset("mission", DB_OPEN_DYNASET)
     
                                            tmi.AddNew
                                            tmi![nomission] = nomission
                                            tmi![lieum] = lieum
                                            tmi![cpm] = cpm
                                            tmi![villem] = villem
                                            tmi.Update
                                        End If
     
                                        'enregistrement du conducteur de travaux si nouveaux
                                        'vérification existence conduct de travaux
                                        If conductexist = 0 Then
                                            Set tverifconduct = bd.OpenRecordset("condtravaux", DB_OPEN_DYNASET)
                                            tverifconduct.AddNew
                                            tverifconduct![noconduct] = Me.noconduct
                                            tverifconduct![nomconduct] = nomconduct
                                            tverifconduct.Update
                                        End If
     
                                        'enregistrement de la tache si nouvelle
                                        If tacheexist = 0 Then
                                            Set ttache = bd.OpenRecordset("tache", DB_OPEN_DYNASET)
                                            ttache.AddNew
                                            ttache![notache] = Me.notache
                                            ttache![nomtache] = taches
                                            ttache.Update
                                        End If
     
                                        'enregistrement de l'intérimaire
                                        'vérification si l'interimaire existait ou non
                                        verif = "SELECT Count(interimaire.nosecu) AS nb from interimaire where nosecu='" + Me.nosecu + "'"
                                        Set tverif = bd.OpenRecordset(verif, DB_OPEN_DYNASET)
     
                                        tverif.MoveFirst
                                        'si l'interimaire n'existe pas alors on va le créer
                                        If tverif![nb] = 0 Then
                                            Set tin = bd.OpenRecordset("interimaire", DB_OPEN_DYNASET)
                                            tin.AddNew
                                            tin![nosecu] = Me.nosecu
                                            tin![nomi] = nomi
                                            tin![prenomi] = prenomi
                                            tin![datenaiss] = datenaiss
                                            tin![depnaiss] = depnaiss
                                            tin![adressei] = adressei
                                            tin![cpi] = cpi
                                            tin![villei] = villei
                                            tin![sexe] = sexe
                                            If satisfait.Value = 1 Then
                                                tin![satisfait] = True
                                            Else
                                                If satisfait.Value = 2 Then
                                                    tin![satisfait] = False
                                                End If
                                            End If
                                            tin![observations] = observation
                                            tin![noagence] = nomagence.Column(1)
                                            tin.Update
                                        Else
                                            critere = "nosecu='" + nosecu + "'"
                                            Set tin = bd.OpenRecordset("interimaire", DB_OPEN_DYNASET)
     
                                            tin.FindFirst critere
                                            'l'interimaire existe deja on met à jour l'adresse, le cp, la ville, la note et l'observation
                                            tin.Edit
                                            tin![adressei] = adressei
                                            tin![cpi] = cpi
                                            tin![villei] = villei
                                            If satisfait.Value = 1 Then
                                                tin![satisfait] = True
                                            Else
                                                If satisfait.Value = 2 Then
                                                    tin![satisfait] = False
                                                End If
                                            End If
                                            tin![observations] = observation
                                            tin.Update
                                        End If
     
                                        'enregistrement du contrat
                                        Set tct = bd.OpenRecordset("contrat", DB_OPEN_DYNASET)
     
                                        tct.AddNew
                                        tct![nocontrat] = Me.noc
                                        tct![datedeb] = datedebc
                                        tct![datefin] = datefinc
                                        tct![statut] = statut
                                        tct![emploi] = emploi
                                        tct![qualif] = qualif
                                        tct![coef] = coef
                                        If Me!basecs <> "" Then
                                            tct![basecontrat] = basecs
                                        End If
                                        If Me!bcr <> "" Then
                                            tct![basecontratref] = bcr
                                        End If
                                        If Me!coefbc <> "" Then
                                            tct![coefbc] = coefbc
                                        End If
                                        If Me!primetrajet <> "" Then
                                            tct![primetrajet] = primetrajet
                                        End If
                                        If Me!coeftrajet <> "" Then
                                            tct![coeftrajet] = coeftrajet
                                        End If
                                        If Me!primepc <> "" Then
                                            tct![primepanier] = primepc
                                        End If
                                        If Me!coefpcnc <> "" Then
                                            tct![coefpaniernonchar] = coefpcnc
                                        End If
                                        If Me!indemnitetrspt <> "" Then
                                            tct![indemnitetrspt] = indemnitetrspt
                                        End If
                                        If Me!coeftrspt <> "" Then
                                            tct![coeftrspt] = coeftrspt
                                        End If
                                        If Me!kms <> "" Then
                                            tct![kms] = kms
                                        End If
                                        If Me!indemnitepc <> "" Then
                                            tct![indemnitepanier] = indemnitepc
                                        End If
                                        If Me!coefpcc <> "" Then
                                            tct![coefpanierchar] = coefpcc
                                        End If
                                        tct![txhf] = Round(Me.txhfact, 2)
                                        tct![nosecu] = nosecu
                                        tct![noagence] = noagence
                                        tct![nomission] = nomission
                                        tct![nosociete] = nosociete
                                        tct![motifcontrat] = motif
                                        tct![noconduct] = noconduct
                                        tct![notache] = Me.notache
                                        tct![autreindem] = Me.autreindemn
                                        tct![detailautreindemn] = Me.detailindemn
     
                                        tct.Update
     
                                        MsgBox "L'enregistrement s'est bien déroulé"
                                        nomagence.Requery
                                        lieum.Requery
                                        noc = ""
                                        nomagence.Visible = True
                                        nomagence = ""
                                        adressea = ""
                                        villa = ""
                                        lieum.Visible = True
                                        lieum = ""
                                        cpm = ""
                                        villem = ""
                                        nosecu = ""
                                        nationalite.Enabled = True
                                        nationalite = ""
                                        datenaiss.Enabled = True
                                        datenaiss = ""
                                        sexe.Enabled = True
                                        sexe = ""
                                        nomi.Enabled = True
                                        nomi = ""
                                        depnaiss = ""
                                        prenomi.Enabled = True
                                        prenomi = ""
                                        adressei = ""
                                        cpi = ""
                                        villei = ""
                                        satisfait.Value = ""
                                        observation = ""
                                        datedebc = ""
                                        datefinc = ""
                                        statut = ""
                                        emploi = ""
                                        qualif = ""
                                        coef = ""
                                        basecs = ""
                                        primetrajet = ""
                                        primepc = ""
                                        indemnitetrspt = ""
                                        kms = ""
                                        indemnitepc = ""
                                        renouvellement.Value = ""
                                        datedebr = ""
                                        datefinr = ""
                                        motif = ""
                                        nomconduct = ""
                                        coefbc = ""
                                        coefpcnc = ""
                                        coefpcc = ""
                                        coeftrajet = ""
                                        coeftrspt = ""
                                        bcr = ""
                                        depnaiss.Enabled = True
                                        depnaiss.Locked = False
                                        taches = ""
                                        txhfact = ""
                                        Me.daterenouv.Requery
                                        Me.autreindemn = ""
                                        Me.detailindemn = ""
     
                                        'demande à l'utilisateur s'il veut changer de société pour le nouveau contrat
                                        Dim b As String
                                        b = MsgBox("Voulez vous changer de société ?", vbYesNo, "Félicitations")
                                        If b = 6 Then
                                            DoCmd.OpenForm "frmsociete"
                                        End If
                                    Else
                                        MsgBox "Veuillez saisir une Tâche", vbOKOnly, "ATTENTION"
                                    End If
                                Else
                                    MsgBox "Veuillez saisir une date de début et une date de fin de contrat", vbOKOnly, "ATTENTION"
                                End If
                            Else
                                MsgBox "Vous avez oublié de rentrer un numéro de sécurité sociale", vbOKOnly, "ATTENTION"
                            End If
                        Else
                            MsgBox "Veuillez saisir une base de contrat de référence", vbOKOnly, "ATTENTION"
                        End If
                    Else
                        MsgBox "Veuillez saisir une base de contrat", vbOKOnly, "ATTENTION"
                        Exit Sub
                    End If
                Else
                    MsgBox "Veuillez saisir un lieu de mission", vbOKOnly, "ATTENTION"
                    Exit Sub
                End If
            Else
                MsgBox "Veuillez saisir une agence", vbOKOnly, "ATTENTION"
                Exit Sub
            End If

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2007
    Messages : 5
    Par défaut
    a la fin je termine les boucles mais y avait plus assez de place dans le petit carré

  5. #5
    Membre émérite Avatar de jean-paul lepetit
    Inscrit en
    Février 2005
    Messages
    849
    Détails du profil
    Informations personnelles :
    Âge : 69

    Informations forums :
    Inscription : Février 2005
    Messages : 849
    Par défaut
    Salut,

    Déja, ta gestion d'erreur ne se met pas en début mais en fin
    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
     
    Sub XXXXX()
    On Error GoTo GestionErreur:
    Dim bd As Database
    Dim tage As Recordset, tin As Recordset
    Dim tct As Recordset, tmi As Recordset, treq As Recordset, tverif As Recordset, texist As Recordset
    Dim req As String, verif As String, critere As String, exist As String, critere2 As String
    Dim missionex As String, verifconduct As String, veriftache As String
    Dim tverifconduct As Recordset, tconduct As Recordset, ttache As Recordset, tveriftache As Recordset
    Dim tre As Recordset
     
    Set bd = DBEngine.Workspaces(0).Databases(0)
     
    If Me.noc.Value <> "" Then
    'vérification existence du contrat pr savoir si Nveau ou MAJ
    exist = "select count(nocontrat) as num from contrat where nocontrat='" + Me.noc + "'"
    Set texist = bd.OpenRecordset(exist, DB_OPEN_DYNASET)
    'Etc......
    Exit Sub
    GestionErreur:
    If Err.Number = 3421 Then
    MsgBox "Vous avez saisi du texte dans un champ numérique. Veuillez vérifier vos informations.", vbOKOnly, "ATTENTION"
    Exit Sub
    End If
    If Err.Number = 3163 Then
    MsgBox "Vous ne pouvez pas ajouter de motif. Veuillez choisir un motif dans la zone de liste.", vbOKOnly, "ATTENTION"
    Exit Sub
    End If
    End Sub
    et c'est peut être à cause de ta gestion d'erreur que ta procédure bouclait.

    autrement, tu peux mettre un point d'arrêt au début de ta procédure et la faire dérouler pas à pas et tu comprendras pourquoi tu boucles

Discussions similaires

  1. executer un batch sans quitter dos à la fin
    Par maa dans le forum Scripts/Batch
    Réponses: 3
    Dernier message: 19/06/2007, 17h20
  2. [SQL SERVER 2000] Fonction utilisateur : boucle sans fin
    Par galinijay dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 30/09/2005, 16h03
  3. [Struts]Executer une action sans ActionForm associé ?
    Par brousaille dans le forum Struts 1
    Réponses: 7
    Dernier message: 19/09/2005, 17h24
  4. WaitForCompletion sans fin
    Par Brunoo dans le forum DirectX
    Réponses: 3
    Dernier message: 09/09/2004, 18h12
  5. Réponses: 4
    Dernier message: 04/04/2004, 13h59

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