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
| Sub actualisation_tables()
Dim alpha_table As TableDef
Dim beta_table As TableDef
Dim alpha_fields As Field
Dim beta_fields As Field
Dim trouver As Boolean
For Each alpha_table In CurrentDb.TableDefs
Select Case True
' Tables systèmes
Case alpha_table.Name Like "MSys*"
' Tables importées
Case alpha_table.Name Like "E1C_*"
' On parcours chacunes des tables afin de trouver celle qui correspond à la table importée
For Each beta_table In CurrentDb.TableDefs
' Cas où la table correspondante est trouvée
If beta_table.Name = Right(alpha_table.Name, Len(alpha_table.Name) - 4) Then
' On parcours les champs de la table importée
For Each alpha_fields In alpha_table.Fields
trouver = False
' On parcours les champs de l'ancienne table
For Each beta_fields In beta_table.Fields
If UCase(alpha_fields.Name) Like UCase(beta_fields.Name) Then
beta_fields.Type = alpha_fields.Type
beta_fields.Size = alpha_fields.Size
trouver = True
Exit For
End If
Next beta_fields
If trouver = False Then
beta_table.CreateField alpha_fields.Name, alpha_fields.Type, alpha_fields.Size
End If
Next alpha_fields
' Penser à supprimer la table afin d'accélérer la suite
DoCmd.DeleteObject acTable, alpha_table.Name
Exit For
End If
Next beta_table
' Tables anciennes
Case Else
' Rien pour le moment
End Select
Next alpha_table
End Sub |
Partager