Bonjour a tous,
Je voudrais faire une focntion capable de me générer un identifiant de ma table. Mes identifiants seront 1,2,3,4,5, etc...
Je fais un test avant d'aplé mon code pour voir si ma requete retourne quelquechose pour verifier qu'il y a bien quelquechose dans ma table, avant de lancer ma fonction.
Mais j'ai un soucis lorsque j'execute mon code, l'identifiant 2 est généré puis le 3 mais après ca s'arete la et il me relande 3 donc ca plante puisqu'on ne peut pas avoir 2 identifiants identique.
Quelqu'un voit mon erreur?
Voici le code :
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 Public Function get_id(recordset, nomchamp As String) As Integer 'mes variables Dim bool As Boolean 'MsgBox ("le premier id est : " & nomchamp) MsgBox ("nombre d'enregistrement est : " & recordset.RecordCount) 'recordset.MoveLast recordset.MoveFirst 'récupération du premier identifiant get_id = nomchamp get_id = get_id + 1 recordset.MoveNext '---parourir le recordset Do While recordset.EOF = False and bool = False If get_id = nomchamp Then get_id = nomchamp + 1 Else get_id = get_id + 1 bool = True End If recordset.MoveNext Loop End Function
Partager