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
| Private Function estIndexUiquefPrimaire(prmDB As DAO.Database, prmNomTable As String, prmListeNomChamp As Collection) As Boolean
'prmDB est la base en cours d'analyse
'prmNomTable est la table inspectée pour déterminer si la liste de champs constituent un index unique
'prmListeNomChamp est la liste des noms des champs constituant la relation entre les table
Dim result As Boolean: result = False
Dim i As DAO.Index
Dim f As DAO.Field
Dim cptEstDansIndex As Long
Dim nomChamp As Variant
For Each i In prmDB.TableDefs(prmNomTable).Indexes
Debug.Print , prmNomTable, i.Name, i.Fields.Count: DoEvents
If (i.Unique Or i.Primary) And i.Fields.Count = prmListeNomChamp.Count Then
cptEstDansIndex = 0
For Each f In i.Fields
Debug.Print , , f.Name: DoEvents
For Each nomChamp In prmListeNomChamp
If f.Name = nomChamp Then
cptEstDansIndex = cptEstDansIndex + 1
Exit For
End If
Next nomChamp
Next f
If cptEstDansIndex <> i.Fields.Count Then
result = False
Else
result = True
End If
End If
If result = True Then
'On a trouvé un index unique qui correspond aux champs
Exit For
End If
Next i
estIndexUiquefPrimaire = result
End Function |
Partager