Vba / access incrémentation

Fermé
Destinos - Modifié par Destinos le 8/12/2011 à 17:28
 Utilisateur anonyme - 8 déc. 2011 à 18:46
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

Utilisateur anonyme
8 déc. 2011 à 18:46
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