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 :

Erreur 3021 alors que données


Sujet :

VBA Access

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 6
    Points : 2
    Points
    2
    Par défaut Erreur 3021 alors que données
    Bonjour,

    Je m'occupe d'une base de données access qui a été programmée pour être mise à jour à partir d'une autre base de données access. Les mises à jours s'effectuaient très bien jusqu'à ce que hier il me signale une "erreur 3021 aucune enregistrement en cours". Cette erreur ne s'est jamais produite auparavant et le débogue me surligne une ligne mais je ne comprends pas pourquoi. Pourriez-vous m'aider à y voir plus claire SVP??

    Merci d'avance pour les réponses, c'ets pour le boulot et cette mise à jour est très urgente!

    Voici le code mis en avant par le débogeur:
    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
    Option Compare Database
    
    Global liste(100, 100)
    Global var As String
    Global fin As Integer
    Global x As Integer
    Global a As Integer
    Global b As Integer
    Global max As Integer
    Global model As String
    Global datedeb As String
    Global datefin As String
    Global dtdeb As String
    Global dtfin As String
    Global cat As String
    Global avancement As Long
    Global anmax As Integer
    
    Sub recherche_variante()
    
    DoCmd.OpenForm ("mo")
    Erase liste
    Dim rst As Recordset
    Dim avancemt As Recordset
    Dim n As Integer
    DoCmd.SetWarnings False
    
    Set avancemt = CurrentDb.OpenRecordset("select max(avance) as av from avancem")
    avancement = (avancemt!av)
    
    'On récupère la 1ere variante de la base
    SQL_LIGNE = "SELECT * FROM recherche where var<>''"
    Set rst = CurrentDb.OpenRecordset(SQL_LIGNE)
    
    rst.MoveFirst
    rst.Move (avancement)
    
    'On se déplace dans le recordset pour récuperer les variantes une à une
    Do
    datedeb = ""
    datefin = ""
    var = ("rst!var")
    model = ("rst!lib_cplt")
    dtdeb = ""
    dtfin = ""
    cat = ("rst!num_cat")
    
    If Not (rst!date_debut) Then
    datedeb = (rst!date_debut)
    End If
    If Not (rst!date_fin) Then
    datefin = (rst!date_fin)
    End If
    
    If Not (rst!aff_dtdeb) Then
    dtdeb = (rst!aff_dtdeb)
    End If
    If Not (rst!aff_dtfin) Then
    dtfin = (rst!aff_dtfin)
    End If
    
    
    Forms!mo!texte0 = model
    Forms!mo![date_debut] = datedeb
    Forms!mo![date_fin] = datefin
    Forms!mo![aff_dtdeb] = dtdeb
    Forms!mo![aff_dtfin] = dtfin
    
    Dim rst2 As Recordset

  2. #2
    Membre chevronné
    Inscrit en
    Août 2006
    Messages
    1 588
    Détails du profil
    Informations forums :
    Inscription : Août 2006
    Messages : 1 588
    Points : 2 178
    Points
    2 178
    Par défaut
    l'erreur 3021 correspond à adErrNoCurrentRecord
    Il n'y a pas d'enregistrement en cours, tester avec un rst.EOF

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 6
    Points : 2
    Points
    2
    Par défaut
    Merci pour ta réponse,
    Mais je ne vois pas comment intégrer la fonciton EOF dans le code. Cette base a été créée par un autre je ne fais que la récupérer.
    Et surtout je ne comprends pas pourquoi d'un coup il considère qu'il n'y a plus d'enregistrement. As-tu une idée?

  4. #4
    Membre chevronné
    Inscrit en
    Août 2006
    Messages
    1 588
    Détails du profil
    Informations forums :
    Inscription : Août 2006
    Messages : 1 588
    Points : 2 178
    Points
    2 178
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Set rst = CurrentDb.OpenRecordset(SQL_LIGNE)
    If Not rst.EOF Then
     rst.MoveFirst
     rst.Move (avancement)
    
     'On se déplace dans le recordset pour récuperer les variantes une à une
     Do Until rst.EOF
    
     ............

  5. #5
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 6
    Points : 2
    Points
    2
    Par défaut
    J'ai essayé le rst.EOF mais ça me met toujours le même bug: "erreur 3021"...
    Je commence à désespérer...

  6. #6
    Membre régulier
    Inscrit en
    Juin 2009
    Messages
    114
    Détails du profil
    Informations forums :
    Inscription : Juin 2009
    Messages : 114
    Points : 108
    Points
    108
    Par défaut
    sur quelle ligne tu as l'erreur ?
    normalement en utilisant le .eof et en englobant bien le code concerné par le recordset avec cette condition ça devrait marcher

    vérifie quand même si tu as bien des lignes dans tes tables "avancemen" (bien orthographié ?) et "recherche"

  7. #7
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 6
    Points : 2
    Points
    2
    Par défaut
    J'ai surligné en rouge et gras la ligne d'erreur même si je ne pense pas que ça vienne de là.
    Comme je l'ai dit j'ai récupéré cette base et en y regardant de plus près j'ai vu qu'il existe une table "avancem" avec une ligne "avance" mais à part dans cette table et dans ce module je ne le retrouve nul part ailleurs. Peut être a t'il été modifié et le changement n'a pas été fait dans ce module. Je suis tellement perdu...!

    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
    Option Compare Database
    
    Global liste(100, 100)
    Global var As String
    Global fin As Integer
    Global x As Integer
    Global a As Integer
    Global b As Integer
    Global max As Integer
    Global model As String
    Global datedeb As String
    Global datefin As String
    Global dtdeb As String
    Global dtfin As String
    Global cat As String
    Global avancement As Long
    Global anmax As Integer
    
    Sub recherche_variante()
    
    DoCmd.OpenForm ("mo")
    Erase liste
    Dim rst As Recordset
    Dim avancemt As Recordset
    Dim n As Integer
    DoCmd.SetWarnings False
    
    Set avancemt = CurrentDb.OpenRecordset("select max(avance) as av from avancem")
    avancement = (avancemt!av)
    
    'On récupère la 1ere variante de la base
    SQL_LIGNE = "SELECT * FROM recherche where var<>''"
    Set rst = CurrentDb.OpenRecordset(SQL_LIGNE)
    
    If Not rst.EOF Then
     rst.MoveFirst
     rst.Move (avancement)
    
    'On se déplace dans le recordset pour récuperer les variantes une à une
    
    Do Until rst.EOF
    datedeb = ""
    datefin = ""
    var = (rst!var)
    model = (rst!lib_cplt)
    dtdeb = ""
    dtfin = ""
    cat = (rst!num_cat)
    
    If Not (rst!date_debut) Then
    datedeb = (rst!date_debut)
    End If
    If Not (rst!date_fin) Then
    datefin = (rst!date_fin)
    End If
    
    If Not (rst!aff_dtdeb) Then
    dtdeb = (rst!aff_dtdeb)
    End If
    If Not (rst!aff_dtfin) Then
    dtfin = (rst!aff_dtfin)
    End If
    
    
    Forms!mo!texte0 = model
    Forms!mo![date_debut] = datedeb
    Forms!mo![date_fin] = datefin
    Forms!mo![aff_dtdeb] = dtdeb
    Forms!mo![aff_dtfin] = dtfin
    
    Dim rst2 As Recordset
    
    'On regarde s'il y a des véhicules ac ce code modèle
    
    If datedeb <> "" And datefin <> "" Then
        If dtdeb <> "" And dtfin <> "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "' And date_fab >#" & Forms!mo!date_debut & "# And date_fab < #" & Forms!mo!date_fin & "# And date_fab >#" & Forms!mo!aff_dtdeb & "# And date_fab < #" & Forms!mo!aff_dtfin & "#"
        Else
        If dtdeb <> "" And dtfin = "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "' And date_fab >#" & Forms!mo!date_debut & "# And date_fab < #" & Forms!mo!date_fin & "# And date_fab >#" & Forms!mo!aff_dtdeb & "#"
        Else
        If dtdeb = "" And dtfin <> "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "' And date_fab >#" & Forms!mo!date_debut & "# And date_fab < #" & Forms!mo!date_fin & "# And date_fab < #" & Forms!mo!aff_dtfin & "#"
        Else
        If dtdeb = "" And dtfin = "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "' And date_fab >#" & Forms!mo!date_debut & "# And date_fab < #" & Forms!mo!date_fin & "#"
        End If
        End If
        End If
        End If
    Else
    If datedeb <> "" And datefin = "" Then
        If dtdeb <> "" And dtfin <> "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "' And date_fab >#" & Forms!mo!date_debut & "# And date_fab >#" & Forms!mo!aff_dtdeb & "# And date_fab < #" & Forms!mo!aff_dtfin & "#"
        Else
        If dtdeb <> "" And dtfin = "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "' And date_fab >#" & Forms!mo!date_debut & "# And date_fab >#" & Forms!mo!aff_dtdeb & "#"
        Else
        If dtdeb = "" And dtfin <> "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "' And date_fab >#" & Forms!mo!date_debut & "# And date_fab < #" & Forms!mo!aff_dtfin & "#"
        Else
        If dtdeb = "" And dtfin = "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "' And date_fab >#" & Forms!mo!date_debut & "#"
        End If
        End If
        End If
        End If
    Else
    If datedeb = "" And datefin <> "" Then
        If dtdeb <> "" And dtfin <> "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "' And date_fab < #" & Forms!mo!date_fin & "# And date_fab >#" & Forms!mo!aff_dtdeb & "# And date_fab < #" & Forms!mo!aff_dtfin & "#"
        Else
        If dtdeb <> "" And dtfin = "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "' And date_fab < #" & Forms!mo!date_fin & "# And date_fab >#" & Forms!mo!aff_dtdeb & "#"
        Else
        If dtdeb = "" And dtfin <> "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "' And date_fab < #" & Forms!mo!date_fin & "# And date_fab < #" & Forms!mo!aff_dtfin & "#"
        Else
        If dtdeb = "" And dtfin = "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "' And date_fab < #" & Forms!mo!date_fin & "#"
        End If
        End If
        End If
        End If
    Else
    If datedeb = "" And datefin = "" Then
        If dtdeb <> "" And dtfin <> "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "'And date_fab >#" & Forms!mo!aff_dtdeb & "# And date_fab < #" & Forms!mo!aff_dtfin & "#"
        Else
        If dtdeb <> "" And dtfin = "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "' And date_fab >#" & Forms!mo!aff_dtdeb & "#"
        Else
        If dtdeb = "" And dtfin <> "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "' And date_fab < #" & Forms!mo!aff_dtfin & "#"
        Else
        If dtdeb = "" And dtfin = "" Then
        texte = "SELECT * FROM nouveaux_vi WHERE modele_cpi='" & model & "'"
        End If
        End If
        End If
        End If
    End If
    End If
    End If
    End If
    
    Set rst2 = CurrentDb.OpenRecordset(texte)
    
    If rst2.EOF = False Then
    
    'On vide le tableau des variantes
    Erase liste
    
    'On remplis la 1ère cellule du tableau avec la 1ère variante
    liste(1, 1) = Right(Left(var, 5), 5)
    a = 1
    b = 1
    'Initialisation des paramètres
    x = 5
    
    'On passe en revue tous les caractères de la variante
    For x = 5 To Len(var)
    
    'Si le caractère est + on ajoute les 5 champs suivants dans le tableau
    If Right(Left(var, x), 1) = "+" Then
    
    a = a + 1
    
    liste(b, a) = Right(Left(var, x + 5), 5)
    
    Else
    
    'Si le caractère est /
    
    If Right(Left(var, x), 1) = "/" Then
    
    fin = x - 1 '=fin de la variante d'origine
    
    Call slash
    
    End If
    End If
    
    Next x
    
    DoCmd.RunSQL ("delete * from vari")
    
    'On rempli un tableau avec les différentes variantes
    For c = 1 To 100
    For l = 1 To 100
    If liste(l, c) <> "" Then
    DoCmd.RunSQL ("insert into vari (champ" & c & ") values ('" & liste(l, c) & "')")
    max = c
    End If
    Next l
    Next c
    
    Call recherche
    End If
    rst.Move 1
    
    avancement = avancement + 1
    
    DoCmd.RunSQL ("insert into avancem values (" & avancement & ")")
    
    Loop
    End If
    End Sub
    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
    Function slash()
     
    b = b + 1
    début = x - 1 'début de la partie variable étudiée
     
    'On passe les caractères en revue jusqu'au prochain + ou / ou la fin de la variable
    Do
    x = x + 1
    Loop Until Right(Left(var, x), 1) = "/" Or Right(Left(var, x), 1) = "+" Or x = Len(var)
     
    If x = Len(var) Then
    nb = x 'Si fin de la var nb=x
    Else
    nb = x - 1 'sinon nb=x-1 car x est le caractère + ou /
    End If
     
    'longueur de la partie variable de la variante:
    longueur = nb - (début + 1)
     
    liste(b, a) = Right(Left(var, fin - longueur), 5 - longueur) & Right(Left(var, nb), longueur)
     
    If Right(Left(var, x), 1) = "/" Then
     
    Call slash
     
    Else
     
    x = x - 1
     
    End If
     
    End Function
    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
    Function recherche()
     
    Dim sel As String
     
    sel = "insert into resultats([num_cat], date_debut, date_fin, [code modèle],variantes, debut, fin, année, nombre) select '" & cat & "','" & datedeb & "', '" & datefin & "', '" & model & "', '" & var & "','" & dtdeb & "','" & dtfin & "',year(req1.date_fab), count(req1.id_interne) from req1"
     
    For s = 2 To max
    'On complète la requete finale qui servira a joindre toutes les tables
    sel = sel & ", req" & s 'Partie select...from
    If s = 2 Then 'Si 1ère condition
    WHERE = " where req1.id_interne=req" & s & ".id_interne" 'Partie where....
    Else 'Pour les conditions suivantes on rajoute le and
    WHERE = WHERE & " and req1.id_interne=req" & s & ".id_interne" 'Partie where....
    End If
    Next s
     
    WHERE = WHERE & " group by year(req1.date_fab)"
     
     
    SQL = sel & WHERE
    DoCmd.RunSQL (SQL)
     
     
    End Function
    '

  8. #8
    Membre régulier
    Inscrit en
    Juin 2009
    Messages
    114
    Détails du profil
    Informations forums :
    Inscription : Juin 2009
    Messages : 114
    Points : 108
    Points
    108
    Par défaut
    est-ce que le champ date_debut existe bien ou est orthographié de la même manière dans la table recherche ?

    avant l'erreur, est ce que les variables var ,model et cat récupèrent bien une valeur ?

  9. #9
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 6
    Points : 2
    Points
    2
    Par défaut
    Excuse moi pour le temps de réponse, j'étais absente du bureau. Oui date_debut est bien ortographié. Et toutes les variables ont bien une valeur, le seul message d'erreur était le 3021. Je me repenche dessus aujourd'hui et je vous tiens au courant. Merci beaucoup pour votre aide!!

  10. #10
    Expert éminent sénior

    Avatar de Tofalu
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Octobre 2004
    Messages
    9 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Octobre 2004
    Messages : 9 501
    Points : 32 311
    Points
    32 311
    Par défaut
    Que vaut avancement ?

Discussions similaires

  1. [AC-2007] Doublon de données alors que donnée indexée sans doublon
    Par Lyysis dans le forum IHM
    Réponses: 6
    Dernier message: 22/07/2013, 10h24
  2. WMS Webkit Erreur 403 alors que Gecko est OK
    Par olivier_f dans le forum IGN API Géoportail
    Réponses: 3
    Dernier message: 08/09/2011, 20h00
  3. erreur noclassdeffounderror alors que présent dans lib
    Par molesqualeux dans le forum Servlets/JSP
    Réponses: 2
    Dernier message: 12/03/2010, 08h36
  4. [MySQL] Erreur sql alors que la requête est correcte sur mysql
    Par toshiro92 dans le forum PHP & Base de données
    Réponses: 7
    Dernier message: 08/04/2009, 23h58
  5. Réponses: 1
    Dernier message: 11/01/2009, 00h57

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