Vba / access incrémentation

Destinos -  
 Utilisateur anonyme -
Bonjour,
voila j'aimerai incrémenter une variable lors d'une erreur/doublon (3022) en vba;
je bosse sur ce code actuellement mais l'incrementation ne s'opère pas correctement:

Function Insertion(oRst1 As DAO.Recordset, orst2 As DAO.Recordset) As Integer
On Error GoTo err
Dim nb As Integer
Dim Fld As DAO.Field
nb = 0
orst2.AddNew
For Each Fld In oRst1.Fields
If (Fld.Attributes And dbAutoIncrField) = 0 Then
orst2.Fields(Fld.Name).Value = Fld.Value
End If

Next Fld
orst2.Update
err:
Select Case err.Number
Case 3022
nb = nb + 1
Insertion = nb
End Select
End Function

merci de m'aider

1 réponse

  1. Utilisateur anonyme
     
    Bonjour,

    De mémoire :

    nb = 0 
    
    orst2.Edit
    
    orst2.AddNew 
    For Each Fld In oRst1.Fields 
    If (Fld.Attributes And dbAutoIncrField) = 0 Then 
        orst2.Fields(Fld.Name).Value = Fld.Value 
    End If 
    Next Fld 
    orst2.Update 
    


    Cdt

    Lupin
    0